
The same migration could also have been written without using revert but this would have involved a few more steps: reversing the order of create_table and reversible, replacing create_table by drop_table, and finally replacing up by down and vice-versa. class DontUseConstraintForZipcodeValidationMigration < ActiveRecord::Migration For example, let's imagine that CreateBlock is committed and it is later decided it would be best to use Active Record validations, in place of the CHECK constraint, to verify the zipcode. This could be useful to revert selected parts of previous migrations. The revert method also accepts a block of instructions to reverse. Go Rhino offers a variety of truck accessories including sidesteps, front guards, winch guards, exhaust tips, bed rails, bed bars, sport bars, and roof racks. You can use Active Record's ability to rollback migrations using the revert method: require_relative '20100905201547_create_blocks'Ĭlass FixupCreateBlock < ActiveRecord::Migration )ĭown 20181003171932 Some migration descriptionĭown 20181004211151 Some migration descriptionĭown 20181005151403 Some migration descriptionįrom Rails Guide Reverting Previous Migrations

Up 20181005151403 Some migration description Up 20181004211151 Some migration description Up 20181003171932 Some migration description Up 20181002222222 Some migration description Up 20181001002039 Some migration description (Note that this uses db:migrate - not db:migrate:down as in other answers to this question.)Īssuming the specified migration version is older than the current version, this will roll back all migrations up to, but not including, the specified version.įor example, if rake db:migrate:status initially displays: (. To roll back all migrations up to a particular version (e.g. If that is not what you intended, you can safely run rake db:migrate and it will re-run only that one, skipping any others that were not previously rolled back.Īnd if you ever want to migrate a single migration out of order, there is also its inverse db:migrate:up: rake db:migrate:up VERSION=20100905201547 Note that this will NOT rollback any interceding migrations - only the one listed. In order to rollback ONLY ONE specific migration (OUT OF ORDER) use: rake db:migrate:down VERSION=20100905201547 To roll back all migrations back to (and including) a target migration, use: (This corrected command was added AFTER all the comments pointing out the error in the original post) rake db:migrate VERSION=20100905201547

Will also rollback all the migration that happened later (4, 3, 2 and also 1). You can substitute 1 for however many migrations you want to go back. Is a way to do this, if the migration you want to rollback is the last one applied.
