【发布时间】:2018-10-31 18:02:09
【问题描述】:
我刚刚迁移了我的 create_supplier 迁移,然后我意识到我的一个数据类型是错误的,所以我添加了另一个迁移,如下所示:-
class ChangePhoneToStringInSuppliers < ActiveRecord::Migration[5.1]
def change
change_column :suppliers, :phone_no_1, :string
change_column :suppliers, :phone_no_2, :string
end
end
迁移后,我意识到我没有推送我的代码,所以理想情况下我应该回滚到 create_suppliers 迁移并在那里自己添加更改。当我回滚 ChangePhoneToStringInSuppliers 时,出现以下错误:-
This migration uses change_column, which is not automatically reversible.
To make the migration reversible you can either:
1. Define #up and #down methods in place of the #change method.
2. Use the #reversible method to define reversible behavior.
我认为上述错误消息(以及互联网上的其他帖子)中建议的方法是对这个问题的预防,而不是治疗(如果我错了,请纠正我)。现在如何回滚此迁移?
【问题讨论】:
标签: ruby-on-rails ruby-on-rails-4 ruby-on-rails-5 database-migration