Rails: How to add add_index to existing table

前端 未结 3 1941
礼貌的吻别
礼貌的吻别 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:26

    Almost

    class AddIndexToUnits < ActiveRecord::Migration
      def self.up
        add_index :units, :lesson_id, :name=>'lesson_index'
      end
    
      def self.down
        remove_index :units, 'lesson_index'
      end
    end
    

提交回复
热议问题