For starters
rake db:rollback
will get you back one step
then
rake db:rollback STEP=n
Will roll you back n
migrations where n
is the number of recent migrations you want to rollback.
More references here.
Roll back the most recent migration:
rake db:rollback
Roll back the n
most recent migrations:
rake db:rollback STEP=n
You can find full instructions on the use of Rails migration tasks for rake on the Rails Guide for running migrations.
Here's some more:
rake db:migrate
- Run all migrations that haven't been run alreadyrake db:migrate VERSION=20080906120000
- Run all necessary migrations (up or down) to get to the given versionrake db:migrate RAILS_ENV=test
- Run migrations in the given environmentrake db:migrate:redo
- Roll back one migration and run it againrake db:migrate:redo STEP=n
- Roll back the last n
migrations and run them againrake db:migrate:up VERSION=20080906120000
- Run the up
method for the given migrationrake db:migrate:down VERSION=20080906120000
- Run the down
method for the given migrationAnd to answer your question about where you get a migration's version number from:
The version is the numerical prefix on the migration's filename. For example, to migrate to version 20080906120000 run
$ rake db:migrate VERSION=20080906120000
(From Running Migrations in the Rails Guides)
Best way is running Particular migration again by using down or up(in rails 4. It's change)
rails db:migrate:up VERSION=timestamp
Now how you get the timestamp. Go to this path
/db/migrate
Identify migration file you want to revert.pick the timestamp from that file name.
If the version is 20150616132425
, then use:
rails db:migrate:down VERSION=20150616132425
Other people have already answered you how to rollback, but you also asked how you could identify the version number of a migration.
rake db:migrate:status
gives a list of your migrations version, name and status (up or down)/db/migrate
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With