如何删除rails中的索引

时间:2022-01-15 04:14:13

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.

我发现我的架构中有两个“survey_id”列,这给我带来了一些问题。具体来说,我需要删除第二个索引,因为我不希望survey_id是唯一的。

 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!

但这些似乎都不起作用。此迁移删除索引的正确语法是什么?我觉得这是基本的,我只是错过了一些愚蠢的东西。提前致谢!

1 个解决方案

#1


12  

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"

#1


12  

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"