Friday, August 12, 2016

How to roll back a migration file in Rails?

Rollback by Given Number of Steps

You can list all the rake tasks in Rails 5 by doing:

rake db -T | grep rollback
Rolls the schema back to the previous version (specify steps w/ STEP=n)

rake db:rollback           
This rollbacks by one version. You can use:

rake db:rollback  STEP=2
to revert the last two migrations and so on. 

Rollback to a Specific Version

Provide the version to db:migrate down:

rake db:migrate down VERSION=20160206120000
You can also go up to a given version:

rake db:migrate up VERSION=20160206120000

No comments:

Post a Comment