2
錯誤說明此代碼不能回滾:爲什麼發生不可逆遷移?
class AddCountToTag < ActiveRecord::Migration
def change
change_table :tags do |t|
t.integer :count
t.index :count
end
end
end
哪裏錯了?
錯誤說明此代碼不能回滾:爲什麼發生不可逆遷移?
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
...我還以爲change_table是一樣的CREATE_TABLE ..謝謝!! – HanXu 2012-03-24 05:06:02