Rolling back a failed Rails migration

后端 未结 9 788
一向
一向 2020-12-07 17:03

How do you roll back a failed rails migration? I would expect that rake db:rollback would undo the failed migration, but no, it rolls back the previous migratio

9条回答
  •  天涯浪人
    2020-12-07 18:03

    To go to a specified version just use:

    rake db:migrate VERSION=(the version you want to go to)
    

    But if a migration fails part way, you'll have to clean it up first. One way would be:

    • edit the down method of the migration to just undo the part of the up that worked
    • migrate back to the prior state (where you started)
    • fix the migration (including undoing your changes to the down)
    • try again

提交回复
热议问题