# Uninitialized constant CreateDb when using rake db:migrate

**URL:** <https://www.ruby-forum.com/t/uninitialized-constant-createdb-when-using-rake-db-migrate/114328>\
**Category:** Rails\
**Created:** [September 11, 2007, 12:55pm UTC](https://www.ruby-forum.com/t/uninitialized-constant-createdb-when-using-rake-db-migrate/114328 "2007-09-11T12:55:20Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![quik77](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/q/dec6dc/32.png) [@quik77](https://www.ruby-forum.com/u/quik77)\
**Post date:** [September 11, 2007, 12:55pm UTC](https://www.ruby-forum.com/t/uninitialized-constant-createdb-when-using-rake-db-migrate/114328/1 "2007-09-11T12:55:20Z")

</div>

Does anyone have any idea why I might be getting this error? I’m using  
sqlite3 with Rails 1.2.3 and ruby 1.8.5 (2006-08-25) [i486-linux]

rake db:migrate --trace  
(in /home/robhu/incremental)  
\*\* Invoke db:migrate (first\_time)  
\*\* Invoke environment (first\_time)  
\*\* Execute environment  
\*\* Execute db:migrate  
rake aborted!

/usr/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active\_support/dependencies.rb:266:in  
`load_missing_constant' /usr/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:452:in `const\_missing’  
/usr/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active\_support/dependencies.rb:464:in  
`const_missing' /usr/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/inflector.rb:250:in `constantize’  
/usr/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active\_support/core\_ext/string/inflections.rb:148:in  
`constantize' /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/migration.rb:366:in `migration\_class’  
/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active\_record/migration.rb:346:in  
`migration_classes' /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/connection_adapters/sqlite_adapter.rb:352:in `inject’  
/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active\_record/migration.rb:342:in  
`each' /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/migration.rb:342:in `inject’  
/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active\_record/migration.rb:342:in  
`migration_classes' /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/migration.rb:330:in `migrate’  
/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active\_record/migration.rb:297:in  
`up' /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/migration.rb:288:in `migrate’  
/usr/lib/ruby/gems/1.8/gems/rails-1.2.3/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/1.8/thread.rb:135: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

trueman% cat db/migrate/001\_create\_db.rb  
class CreateTasks \< ActiveRecord::Migration  
def self.up  
create\_table :tasks do |t|  
t.column :name, :string  
end  
end

def self.down  
drop\_table :tasks  
end  
end

-Rob

–  
[http://www.robhulme.com/](http://www.robhulme.com/)  
[http://robhu.livejournal.com/](http://robhu.livejournal.com/)

Think of how many religions attempt to validate themselves with  
prophecy. Think of how many people rely on these prophecies, however  
vague, however unfulfilled, to support or prop up their beliefs. Yet  
has there ever been a religion with the prophetic accuracy and  
reliability of science? … No other human institution comes close.  
– Carl Sagan

---

<div class="post-metadata">

**Author:** ![quik77](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/q/dec6dc/32.png) [@quik77](https://www.ruby-forum.com/u/quik77)\
**Post date:** [September 12, 2007, 1:08pm UTC](https://www.ruby-forum.com/t/uninitialized-constant-createdb-when-using-rake-db-migrate/114328/2 "2007-09-12T13:08:13Z")

</div>

> Does anyone have any idea why I might be getting this error? I’m using  
> sqlite3 with Rails 1.2.3 and ruby 1.8.5 (2006-08-25) [i486-linux]  
> Aha. The reason was something to do with creating  
> db/migrate/001\_foo.rb myself. When I used the generator it worked  
> fine.

-Rob

–  
[http://www.robhulme.com/](http://www.robhulme.com/)

> **[robhu](https://robhu.livejournal.com/)**
>
> robhu - the new blog in LiveJournal. There should be new interesting records soon.

Saying that Java is good because it works on all platforms is like  
saying anal sex is good because it works on all genders.  
–Anonymous

---

<div class="post-metadata">

**Author:** ![quik77](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/q/dec6dc/32.png) [@quik77](https://www.ruby-forum.com/u/quik77)\
**Post date:** [September 12, 2007, 4:13pm UTC](https://www.ruby-forum.com/t/uninitialized-constant-createdb-when-using-rake-db-migrate/114328/3 "2007-09-12T16:13:41Z")

</div>

On 9/11/07, Robert H. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Does anyone have any idea why I might be getting this error? I’m using  
> sqlite3 with Rails 1.2.3 and ruby 1.8.5 (2006-08-25) [i486-linux]
> 
> trueman% cat db/migrate/001\_create\_db.rb  
> class CreateTasks \< ActiveRecord::Migration

The migration code looks for a class based on the file name of the  
migration. So since your migration file is named 001\_create\_db.rb, it  
strips off the 001\_ part and turns create\_db into the class CreateDb  
and tries to peform CreateDb.up, which can’t be found.

So you need to either name the migration file as 001\_create\_tasks.rb,  
or rename the class to CreateDb.

You found out that the generator keeps things in order for you. If you  
need a migration to add a table, I suggest you generate a model  
instead of a migration. The model generator will create a migration  
for you as it creates the model skeleton.
