rails undo last migration code example

Example 1: rails rollback multiple migrations

rake db:rollback STEP=n 
# n = how many migrations you want to rollback

Example 2: how to reset migrations rails

To rollback all migrations the best solution is:

rake db:migrate VERSION=0
This will rollback any migrations without losing data. Then, run all migrations again with

rake db:migrate

Example 3: rials db down

bin/rails db:migrate:down VERSION=YYYYMMDDHHMMSS

Example 4: rails db:rollback

rake db:rollback VERSION=n
# n = the version you want to rollback to

Tags:

Ruby Example