错误显示此代码无法回滚:
class AddCountToTag < ActiveRecord::Migration
def change
change_table :tags do |t|
t.integer :count
t.index :count
end
end
end
哪里错了?
答案 0 :(得分:2)
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