为什么会出现IrreversibleMigration?

时间:2012-03-23 15:06:59

标签: ruby-on-rails rails-migrations

错误显示此代码无法回滚:

class AddCountToTag < ActiveRecord::Migration
    def change
        change_table :tags do |t|
            t.integer :count
            t.index :count
        end
    end
end

哪里错了?

1 个答案:

答案 0 :(得分:2)

可逆迁移尚不支持

change_tableSee 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