Search code examples
ruby-on-rails-4rails-migrations

Rails 4 throws pending migrations error even if there are no pending migrations


I recently upgraded my app from Rails 3.2.15 to Rails 4.0.4 and rake test fails throwing:

You have 161 pending migrations:
  20111126090934 DeviseCreateUsers
  20111126195631 AddUsernameToUsers
  20111128012039 CreateLocations
  20111129051416 AddConfirmableToDevise
...
Run `rake db:migrate` to update your database then try again.

I am sure, I don't have any pending migrations and the schema_migrations table is up-to date with all the migration version numbers. Also,

[2] pry(main)> ActiveRecord::Migration.check_pending!
  ActiveRecord::SchemaMigration Load (0.4ms)  SELECT `schema_migrations`.* FROM `schema_migrations`
=> nil
[3] pry(main)> 

Since, this is development environment I've also tried to reset db with:

$> rake db:migrate:reset

I am in the process of moving my app from Rails 3.2.15 to Rails 4.0.4. I am at a loss here, not understanding what is happening.

$> rake db:migrate:status

Status   Migration ID    Migration Name
--------------------------------------------------
   up     20111126090934  ********** NO FILE **********
   up     20111126195631  ********** NO FILE **********
   up     20111128012039  ********** NO FILE **********
   up     20111129051416  ********** NO FILE **********
...

Solution

  • This is little weird and frustrating. I had sub-folders in db/migrate directory which, even though older and already migrated, for some reason were getting listed via ActiveRecord::Migrator#pending_migrations and hence the error. Removing the sub-folders Fixed this issue.

    Wondering how this was working in Rails 3 and can't find any documentation whatsoever regarding this.