Ruby on rails 如何扭转不可逆转的迁移

Ruby on rails 如何扭转不可逆转的迁移,ruby-on-rails,Ruby On Rails,我在我的设计迁移中有这个,现在我已经回滚了迁移..我得到了一个错误 def self.down # By default, we don't want to make any assumption about how to roll back a migration when your # model already existed. Please edit below which fields you would like to remove in this migration

我在我的设计迁移中有这个,现在我已经回滚了迁移..我得到了一个错误

def self.down
    # By default, we don't want to make any assumption about how to roll back a migration when your
    # model already existed. Please edit below which fields you would like to remove in this migration.
    raise ActiveRecord::IrreversibleMigration
end
现在,即使在rake db:migrate之后,我也无法访问该模型。如何让它再次发挥作用

不可逆转的迁移并不意味着逆转

您无法逆转不可逆转的迁移

因此,如果迁移是
Down
,您希望它迁移
Up
,只需在
Up
方法中注释内容,然后再次运行迁移


注释内容时,将确保查询或命令不会再次运行,从而导致另一个错误

不可逆的迁移可以在SQL级别上逆转。编写一个ALTER查询来更改rails控制台中的列或任何其他内容

`StandardError: An error has occurred, this and all later migrations canceled:

ActiveRecord::IrreversibleMigration`

然后删除您的迁移文件。

您可以编辑迁移文件,并通过
reversible
更改
方法,然后再次运行迁移

ActiveRecord::Connection.base.execute('your ALTER query')