Rake db:migrate - how do I undo all migrations and redo them

Lucy Weatherford picture Lucy Weatherford · Apr 24, 2013 · Viewed 29.8k times · Source

Is there a quick rake db:rollback command for all of the migrations?

Answer

Alex Falke picture Alex Falke · Apr 24, 2013

Rolling back all migrations

To rollback all migrations the best solution is the one @Claudio Floreani proposed:

rake db:migrate VERSION=0

This will rollback every migration. You can read why this is the best approach in his answer. Then, run all migrations again with

rake db:migrate

Resetting the database

Reset

rake db:migrate:reset #runs db:drop db:create db:migrate

This method drops the database and runs the migrations again.

Loading the last schema

rake db:reset

This method will drop the database and load the data from the last schema.

You can see more information in this post: Difference between rake db:migrate db:reset and db:schema:load

Thanks to @Claudio Floreani and all the users who commented to improve the answer.