ruby-on-railsrails-activerecord

How to remove index in rails


I have found that I have two "survey_id" columns in my schema and that's been causing some problems for me. Specifically I need to remove the second index as I don't want survey_id to be unique.

 add_index "completions", ["survey_id"], name: "index_completions_on_survey_id"
 add_index "completions", ["survey_id"], name: "index_completions_on_survey_id_and_user_id", unique: true

I've tried

def change
  remove_index "completions", ["survey_id"], name => "index_completions_on_survey_id_and_user_id"
end

and

def change
  remove_index "completions", ["survey_id"], name: "index_completions_on_survey_id_and_user_id"
end

But neither of those seems to work. What's the correct syntax for this migration to remove the index? I feel like this is basic and I'm just missing something.


Solution

  • You don't supply the columns in the index when removing one. Try:

    remove_index :completions, name: "index_completions_on_survey_id_and_user_id"