70

I've deleted a table in the database, call it X. db:migrate no longer works. I have a migration file called CreateX. Is there a way to run just that specific migration?

JP Silvashy
  • 44,746
  • 48
  • 146
  • 219
Daniel
  • 15,762
  • 18
  • 63
  • 86

1 Answers1

176
rake db:migrate:redo VERSION=my_version

Or you can go up or down from a specific version:

db:migrate:up VERSION=my_version
db:migrate:down VERSION=my_version
JP Silvashy
  • 44,746
  • 48
  • 146
  • 219
  • 1
    rake db:migrate:redo seems to work for me (db:specific:redo just gives an error, I'm imagining a version issue) – Daniel Aug 22 '09 at 20:01
  • Oops yah, you were right, that was my custom rake task mixed in, but I fixed it those should work well now. – JP Silvashy Aug 22 '09 at 20:03
  • 38
    N.B. If the table has been dropped from the database, `rake db:migrate:up VERSION=my_version` may do _nothing_, because the schema_migrations table still says it is done. In the same situation `rake db:migrate:redo VERSION=my_version` may _fail_ because it cannot drop the table. In this case, comment out the `down` method in the migration temporarily and re-run `rake db:migrate:redo...` – Leo Sep 08 '12 at 11:54