Rails: How to add add_index to existing table

前端 未结 3 1998
礼貌的吻别
礼貌的吻别 2021-02-04 06:55

I already migrated a table called units with several columns. I was wondering how to migrate in a stand alone \'add_index\' to this table using the cmd. Is this code correct:

3条回答
  •  佛祖请我去吃肉
    2021-02-04 07:15

    To remove an index, you must use remove_index with the same table and column specification as the self.up's add_index has. So:

    def self.down
      remove_index :units, :lesson_id
    end
    

    A multi-column index example would be:

    def self.down
      remove_index :units, [:lesson_id, :user_id]
    end
    

提交回复
热议问题