How to rollback just one step using rake db:migrate
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 lastn
migrations and run them againrake db:migrate:up VERSION=20080906120000
- Run theup
method for the given migrationrake db:migrate:down VERSION=20080906120000
- Run thedown
method for the given migration
And 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.