错误表明此代码无法回滚:
class AddCountToTag < ActiveRecord::Migration
def change
change_table :tags do |t|
t.integer :count
t.index :count
end
end
end
哪里错了?
最佳答案
可逆迁移尚不支持
change_table
。 See this comment at the top of the file (引用如下):
# <tt>ActiveRecord::Migration::CommandRecorder</tt> records commands done during
# a migration and knows how to reverse those commands. The CommandRecorder
# knows how to invert the following commands:
#
# * add_column
# * add_index
# * add_timestamps
# * create_table
# * create_join_table
# * remove_timestamps
# * rename_column
# * rename_index
# * rename_table
如果您需要能够反转,可以使用add_column
而不是change_table
:
class AddCountToTag < ActiveRecord::Migration
def change
add_column :tags, :count, :integer
...
end
end
关于ruby-on-rails - 为什么会发生不可逆迁移?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9841584/