[ACCEPTED]-When I run the rake:db migrate command I get an error "Uninitialized constant CreateArticles-rails-migrations

Accepted answer
Score: 119

Be sure that your file name and class name 4 say the same thing(except the class name 3 is camel cased).The contents of your migration 2 file should look something like this, simplified 1 them a bit too:

class CreateArticles < ActiveRecord::Migration   
  def self.up
    create_table :articles do |t|
      t.belongs_to :user, :category
      t.string :title
      t.text :synopsis, :limit => 1000
      t.text :body, :limit => 20000
      t.boolean :published, :default => false
      t.datetime :published_at

  def self.down
    drop_table :articles
Score: 9

It's possible to get the given error if 10 your class names don't match inflections 9 (like acronyms) from config/initializers/inflections.rb.

For example, if your 8 inflections include:

ActiveSupport::Inflector.inflections(:en) do |inflect|
  inflect.acronym 'DOG'

then you might need 7 to make sure the class in your migration 6 is:

class CreateDOGHouses < ActiveRecord::Migration[5.0]

rather than:

class CreateDogHouses < ActiveRecord::Migration[5.0]

Not super common, but if 5 you generate a migration or a model or something, and 4 then add part of it to inflections afterwards 3 it may happen. (The example here will cause 2 NameError: uninitialized constant CreateDOGHouses if your class name is CreateDogHouses, at least with Rails 1 5.)

Score: 3

If you're getting this error and it's NOT 5 because of the migration file name, there 4 is another possible solution. Open the 3 class directly in the migration like this:

class SomeClass < ActiveRecord::Base; end

It 2 should now be possible to use SomeClass within the 1 migration.

Score: 3

The top answer solved for me. Just leaving 7 this here in case it helps.


If your migration 6 file is called


then the class name in your 5 migration file should be


Note: if the class 4 name doesn't match, it will error even if 3 the difference is just a lower case t instead 2 of an upper case 'T' in 'To' - so be careful 1 of that!

More Related questions