After adding migration files in the db/migrate
folder and running rake db:migrate
, I want get back to the previous step, I think using VERSION=n
is the right way to do that, but I don't know the correct value of n to use. Is there any command to check the current n value?
It would be great if anyone could provide full instructions on how to use rake db:migrate
.
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
Best way is running Particular migration again by using down or up(in rails 4. It's change)
Now how you get the timestamp. Go to this path
Identify migration file you want to revert.pick the timestamp from that file name.
For starters
rake db:rollback
will get you back one stepthen
rake db:rollback STEP=n
Will roll you back
n
migrations wheren
is the number of recent migrations you want to rollback.More references here.
Roll back the most recent migration:
Roll back the
n
most recent migrations: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 migrationAnd to answer your question about where you get a migration's version number from:
(From Running Migrations in the Rails Guides)
If the version is
20150616132425
, then use: