Translate

December 23, 2011

How to rollback Rails database migrations

When you want to perform database migrations in rails you use the following command:
rake db:migrate 

If you want to roll back your change you may need to find out what version your database is currently at and then roll back to a previous version:
To find the version use following command:
rake db:migration VERSION=? 

To roll back to previous version:
rake db:migrate VERSION=<version to roll back to>

To use it to roll back your most recent migration simply run:
rake db:rollback

Other posts:
Difference between update_attribute and update_column 
What is different in update_all, update,  update_attribute, update_attributes methods of Active Record
Difference between .nil?, .empty?, .blank?, .present? 
render vs redirect_to in Ruby on Rails

About
Post a Comment