为什么这种迁移不可逆转? (change_table,rename,text)

时间:2012-01-23 23:23:17

标签: ruby-on-rails activerecord migration

我认为这是一个非常简单的迁移。出于某种原因,当我尝试IrreversibleMigrationdb:rollback时出现db:migrate:redo错误。

迁移顺利进行,但我宁愿让它保持可逆。我无法弄清楚为什么它不像书面那样。有什么想法吗?

以下是迁移:

class AddWhyHypAndWhyHypeToStatements < ActiveRecord::Migration
  def change
    change_table :statements do |t|
      t.rename :description, :why_hypocritical
      t.text   :why_hypothetical
    end
  end
end

如果重要,“description”列是文本列。我正在使用Rails 3.1 / Ruby 1.9.2 / PostgreSQL。谢谢你的帮助。

1 个答案:

答案 0 :(得分:21)

看起来Rails在恢复change_table方法方面遇到了麻烦。尝试这样做:

class AddWhyHypAndWhyHypeToStatements < ActiveRecord::Migration
  def change
    rename_column :statements, :description, :why_hypocritical
    add_column :statements, :why_hypothetical, :text
  end
end

您可以在docsRails Guides中看到可以反转的命令列表。

相关问题