Run a single migration file

nan picture nan · Apr 16, 2009 · Viewed 153.5k times · Source

Is there an easy way to run a single migration? I don't want to migrate to a certain version I just want to run a specific one.

Answer

gtd picture gtd · Apr 16, 2009

Assuming fairly recent version of Rails you can always run:

rake db:migrate:up VERSION=20090408054532

Where version is the timestamp in the filename of the migration.

Edit: At some point over the last 8 years (I'm not sure what version) Rails added checks that prevent this from running if it has already been run. This is indicated by an entry in the schema_migrations table. To re-run it, simply execute rake db:migrate:redo VERSION=20090408054532 instead.