3

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 **********
...
Community
  • 1
  • 1
Syed Aslam
  • 8,707
  • 5
  • 40
  • 54

4 Answers4

3

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.

Syed Aslam
  • 8,707
  • 5
  • 40
  • 54
  • I've hit the same problem (also have sub-folders) but I specify a particular sub-folder that Rails should use for migrations for each env in the env config file, yet this is still happening to me for some reason – sixty4bit Oct 22 '15 at 18:26
  • @sixty4bit i am having the same problem, do u have any solution? – Hadas Nov 19 '15 at 07:55
  • How do you instantiate a new ActiveRecord::MIgrator object? I've just started hitting the same issue for my test environment using postgres. This is an odd and frustrating bug since there seems no real information on how to debug it. – James Hamilton Dec 06 '15 at 11:31
2

The most likely reason for this error is that mysqldump is not in your PATH. Rails 4 needs that to create the test database and gives the confusing error about migrations if it's not found.

A default installation of MySQL on OSX does not include mysql or mysqldump in your PATH, you would need to modify your ~/.profile and add something like:

export PATH=$PATH:/usr/local/mysql/bin

Or re-install mysql from homebrew.

Jan M
  • 2,205
  • 21
  • 14
0

To add to Syed's answer:

Instead of removing the subfolders in db/migrate/, you can also rename them to start with a '.'. This worked for me with activerecord 3.2.

Ex: rename db/migrate/archive/ to db/migrate/.archive/

momo
  • 975
  • 1
  • 8
  • 8
-1

As you are trying to run rake test, you need to run the migrations on test environment.

rake db:migrate RAILS_ENV=test

Kirti Thorat
  • 52,578
  • 9
  • 101
  • 108
  • Doesn't help. In fact, when we do rake test, it invokes db:test:prepare which does load the schema and run pending migrations. Please see: http://stackoverflow.com/a/15170024/210273 – Syed Aslam Mar 24 '14 at 18:31