# Migration problem

**URL:** <https://www.ruby-forum.com/t/migration-problem/122000>\
**Category:** Rails\
**Created:** [December 3, 2007, 8:01pm UTC](https://www.ruby-forum.com/t/migration-problem/122000 "2007-12-03T20:01:52Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![winslowly](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/85f322/32.png) [@winslowly](https://www.ruby-forum.com/u/winslowly)\
**Post date:** [December 3, 2007, 8:01pm UTC](https://www.ruby-forum.com/t/migration-problem/122000/1 "2007-12-03T20:01:52Z")

</div>

I use the following steps to create a model and migrate. However when  
it comes running ‘rake db:migrate’ it gave me the following errors. I  
suspect it is due to the fact that I was trying to put everything  
about blog in its own folder. Is this possible with migration or is  
there a different way of putting topics into their own folder. Here  
are the steps that I did.

1. ruby script/generate model ‘blog/post’
2. rake db:migrate

It tried to create a constant ‘CreateBlogPosts’ which I don’t think  
its suppose to. Anyone who can help or suggest  
something would be greatly appreciated. If I can’t do it this way  
I’ll go back to using ‘script/generate model Post’.

Thanks in advance

The error it threw are:

(in /home/naruto/sites/geneva)  
\*\* Invoke db:migrate (first\_time)  
\*\* Invoke environment (first\_time)  
\*\* Execute environment  
\*\* Execute db:migrate  
rake aborted!  
uninitialized constant CreateBlogPosts  
/home/naruto/sites/geneva/vendor/rails/activerecord/lib/…/…/  
activesupport/lib/active\_support/dependencies.rb:266:in  
`load_missing_constant' /home/naruto/sites/geneva/vendor/rails/activerecord/lib/../../ activesupport/lib/active_support/dependencies.rb:452:in`const\_missing’  
/home/naruto/sites/geneva/vendor/rails/activerecord/lib/…/…/  
activesupport/lib/active\_support/dependencies.rb:464:in  
`const_missing' /home/naruto/sites/geneva/vendor/rails/activerecord/lib/../../ activesupport/lib/active_support/inflector.rb:250:in`constantize’  
/home/naruto/sites/geneva/vendor/rails/activerecord/lib/…/…/  
activesupport/lib/active\_support/core\_ext/string/inflections.rb:148:in  
`constantize' /home/naruto/sites/geneva/vendor/rails/activerecord/lib/active_record/ migration.rb:366:in`migration\_class’  
/home/naruto/sites/geneva/vendor/rails/activerecord/lib/active\_record/  
migration.rb:346:in `migration_classes' /home/naruto/sites/geneva/vendor/rails/activerecord/lib/active_record/ connection_adapters/mysql_adapter.rb:248:in`inject’  
/home/naruto/sites/geneva/vendor/rails/activerecord/lib/active\_record/  
migration.rb:342:in `each' /home/naruto/sites/geneva/vendor/rails/activerecord/lib/active_record/ migration.rb:342:in`inject’  
/home/naruto/sites/geneva/vendor/rails/activerecord/lib/active\_record/  
migration.rb:342:in `migration_classes' /home/naruto/sites/geneva/vendor/rails/activerecord/lib/active_record/ migration.rb:330:in`migrate’  
/home/naruto/sites/geneva/vendor/rails/activerecord/lib/active\_record/  
migration.rb:297:in `up' /home/naruto/sites/geneva/vendor/rails/activerecord/lib/active_record/ migration.rb:288:in`migrate’  
/home/naruto/sites/geneva/vendor/rails/railties/lib/tasks/  
databases.rake:4  
/usr/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:392:in `call' /usr/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:392:in`execute’  
/usr/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:392:in `each' /usr/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:392:in`execute’  
/usr/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:362:in `invoke' /usr/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:355:in`synchronize’  
/usr/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:355:in `invoke' /usr/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:1739:in`top\_level’  
/usr/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:1739:in `each' /usr/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:1739:in`top\_level’  
/usr/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:1761:in  
`standard_exception_handling' /usr/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:1733:in`top\_level’  
/usr/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:1711:in `run' /usr/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:1761:in`standard\_exception\_handling’  
/usr/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:1708:in `run' /usr/lib/ruby/gems/1.8/gems/rake-0.7.3/bin/rake:7 /usr/bin/rake:16:in`load’  
/usr/bin/rake:16

---

<div class="post-metadata">

**Author:** ![winslowly](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/85f322/32.png) [@winslowly](https://www.ruby-forum.com/u/winslowly)\
**Post date:** [December 3, 2007, 8:08pm UTC](https://www.ruby-forum.com/t/migration-problem/122000/2 "2007-12-03T20:08:23Z")

</div>

i got a similar error once, when trying to run migrate on a file where  
the classname didn’t match the filename

so if you have a migration file like

001\_create\_blog\_posts.rb

your class definition in the file must be:

class CreateBlogPosts \< ActiveRecord::Migration

nothing else is allowed, camelcase must match underscores

---

<div class="post-metadata">

**Author:** ![winslowly](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/85f322/32.png) [@winslowly](https://www.ruby-forum.com/u/winslowly)\
**Post date:** [December 3, 2007, 8:15pm UTC](https://www.ruby-forum.com/t/migration-problem/122000/3 "2007-12-03T20:15:21Z")

</div>

thanks this worked. However, should migration have created the file  
properly like you mention instead of class CreatePosts \<  
ActiveRecord::Migration?

On Dec 3, 1:08 pm, Thorsten M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![winslowly](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/85f322/32.png) [@winslowly](https://www.ruby-forum.com/u/winslowly)\
**Post date:** [December 3, 2007, 8:20pm UTC](https://www.ruby-forum.com/t/migration-problem/122000/4 "2007-12-03T20:20:03Z")

</div>

winslowly wrote:

> thanks this worked. However, should migration have created the file  
> properly like you mention instead of class CreatePosts \<  
> ActiveRecord::Migration?
> 
> On Dec 3, 1:08 pm, Thorsten M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

only with that syntax:

ruby script/generate model ‘blog\_posts’

your version:

ruby script/generate model ‘blog/post’

isn’t clear to me, maybe to generate a model in a subdirectory? i would  
expect it to generate an error, but sometimes rails is a bit too smart  
and makes ‘something’ out of the input.

---

<div class="post-metadata">

**Author:** ![winslowly](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/85f322/32.png) [@winslowly](https://www.ruby-forum.com/u/winslowly)\
**Post date:** [December 3, 2007, 8:24pm UTC](https://www.ruby-forum.com/t/migration-problem/122000/5 "2007-12-03T20:24:16Z")

</div>

yeah, I was trying to put all models belonging to blog inside its own  
subdirectory.

Again thanks for the help.

On Dec 3, 1:20 pm, Thorsten M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
