How to fix: "rake db:rollback" does not work

Posted . Visible to the public.

When you run rake db:rollback and nothing happens, you are probably missing the latest migration file (or have not migrated yet).

$ rake db:rollback
$ 

If that happens to you, check your migration status.

$ rake db:migrate:status
   up     20160503143434  Create users
   up     20160506134137  Create pages
   up     20160517112656  Migrate pages to page versions
   up     20160518112023  ********** NO FILE **********

When you tell Rails to roll back, it tries to roll back the latest change that was migrated. In the case above, your schema_migrations table contains an entry 20160518112023 that you do not have the corresponding migration file for. Hence, it can not be rolled back and Rails aborts silently.

This happens for example when you migrated on the master branch at some point and changed to a feature branch that does not yet have master's changes.

Or, if you had a migration that was deleted for a good reason, you can go ahead and remove the corresponding line from schema_migrations manually.

Arne Hartherz
Last edit
Dominik Schöler
License
Source code in this card is licensed under the MIT License.
Posted by Arne Hartherz to makandra dev (2016-05-20 12:09)