Reputation: 8807
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 **********
...
Upvotes: 3
Views: 5166
Reputation: 984
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/
Upvotes: 0
Reputation: 8807
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.
Upvotes: 3
Reputation: 2225
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.
Upvotes: 2
Reputation: 53038
As you are trying to run rake test
, you need to run the migrations on test
environment.
rake db:migrate RAILS_ENV=test
Upvotes: -1