迁移未回滚

6

我已经运行了这个迁移:

class AddUniqueToLocationColumnName < ActiveRecord::Migration
  def change
    remove_index :locations, :name
    add_index :locations, :name, unique: true
  end
end

现在我正在尝试回滚,但是显示错误:

标准错误:发生错误,此及后续所有迁移均已取消:remove_index只有在给定:column选项时才可逆转。

我如何将此迁移回滚到之前的版本?


3
尝试将其更改为 remove_index :locations, column: :name。 (将 "try" 翻译为 "尝试","changing" 翻译为 "更改","it" 指代的是前文提到的某个代码或指令,"remove_index" 保持原文不变,":locations" 指代某个表格名称,"column" 翻译为 "列",":name" 指代该表格中的某个列名。) - max
我认为现在你必须手动从迁移中使用remove_index方法删除位置和名称的索引。为此,您可以创建新的迁移或更改为上下状态。 - Sajjad Murtaza
非常感谢,Max。它起作用了。只需要指定“column: :name”而不是仅使用“name” :) - abhishek
1个回答

3
尝试明确定义上下方向:

尝试明确定义上下方向:

class AddUniqueToLocationColumnName < ActiveRecord::Migration
  def self.up
    remove_index :locations, column: :name
    add_index :locations, :name, unique: true
  end

  def self.down
    remove_index :locations, column: :name # remove unique index
    add_index :locations, :name # adds just index, without unique
  end
end

1
还是不行...Max的解决方案可行。只需要将“:name”改为“column: :name”。 :) 我已根据你的代码编辑了我的代码。所以两个都有帮助 ;) - abhishek

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接