删除已命名的索引的唯一性

时间:2014-06-02 05:05:46

标签: postgresql ruby-on-rails-4

我正在尝试从rails 4.1 app中删除postgresql列索引的唯一性。

原始迁移包括:

add_index :customer_action_plan_objectives, :customer_action_plan_id,:unique => true, :name => "plan_id"

我试过了

class ChangeIndexUniquenessCustomerActionPlanObjectives < ActiveRecord::Migration
  def change
    remove_index :customer_action_plan_objectives, :customer_action_plan_id
    add_index :customer_action_plan_objectives, :customer_action_plan_id, :name => "plan_id"
  end
end

但是我收到了一个错误:

Index name 'index_customer_action_plan_objectives_on_customer_action_plan_id' on table 'customer_action_plan_objectives' does not exist

这是由“:name =&gt;”plan_id“”或其他原因导致的问题吗?我目前的解决方案来自this question and answer

1 个答案:

答案 0 :(得分:0)

看起来'remove_index'方法试图从您传递的参数中派生索引名称。但是上面的add_index传递了'name'参数。 我以为我没有使用过这种方法,文档http://apidock.com/rails/ActiveRecord/ConnectionAdapters/SchemaStatements/remove_index表明您可以将名称传递给remove_index。