Read more

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

Arne Hartherz
May 20, 2016Software engineer at makandra GmbH

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
$ 
Illustration online protection

Rails Long Term Support

Rails LTS provides security patches for old versions of Ruby on Rails (2.3, 3.2, 4.2 and 5.2)

  • Prevents you from data breaches and liability risks
  • Upgrade at your own pace
  • Works with modern Rubies
Read more Show archive.org snapshot

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.

Posted by Arne Hartherz to makandra dev (2016-05-20 14:09)