Rolling back a failed Rails migration

后端 未结 9 770
一向
一向 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 17:49

    Alejandro Babio's answer above provides the best current answer.

    One additional detail I want to add:

    When the myfailedmigration migration fails, it is not considered as applied, and this can be verified by running rake db:migrate:status, which would show output similar to the following:

    $  rake db:migrate:status
    database: sample_app_dev
    
     Status   Migration ID    Migration Name
    --------------------------------------------------
       up      20130206203115  Create users
       ...
       ...
       down    20150501173156  Test migration
    

    The residual effect of add_column :assets, :test, :integer being executed on the failed migration will have to be reversed at the database level with a alter table assets drop column test; query.

提交回复
热议问题