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 seem 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 stupid. Thanks in advance!
16, removing the column removes the index.
The change method can be used to drop a column in Rails 4 applications, but should not be used in Rails 3. I updated my answer accordingly. You can also use remove_column :table_name, :column_name, :type, :options within the change method, since if you specify the type reverting the migration is possible.
An index is used to speed up the performance of queries on a database. Rails allows us to create index on a database column by means of a migration. By default, the sort order for the index is ascending. But consider the case where we are fetching reports from the database.
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"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With