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
我在设计迁移中有这个,现在我已经回滚了迁移..我收到了错误
`StandardError: An error has occurred, this and all later migrations canceled:
ActiveRecord::IrreversibleMigration`
现在即使在rake db:migrate之后我也无法访问该模型。如何重新开始这项工作?
答案 0 :(得分:0)
不可逆迁移并不意味着逆转
你无法扭转不可逆转的迁移。
因此,如果迁移为Down
,并且您希望迁移Up
,只需在up
方法中对内容进行评论,然后再次运行迁移。
评论内容时,将确保查询或命令不会再次运行,从而导致其他错误
答案 1 :(得分:0)
难以置信的迁移可以在SQL级别撤消。编写ALTER查询以更改列或Rails控制台中的其他内容,方法是
ActiveRecord::Connection.base.execute('your ALTER query')
之后,删除您的迁移文件。
答案 2 :(得分:-1)
您可以编辑迁移文件,并通过change
更改reversible
方法,然后再次运行迁移。