Rails: Adding an index after adding column

前端 未结 6 770
死守一世寂寞
死守一世寂寞 2020-12-22 22:18

Suppose I created a table table in a Rails app. Some time later, I add a column running:

rails generate migration AddUser_idColumnToTable user_i         


        
6条回答
  •  一向
    一向 (楼主)
    2020-12-22 22:40

    You can use this, just think Job is the name of the model to which you are adding index cader_id:

    class AddCaderIdToJob < ActiveRecord::Migration[5.2]
      def change
        change_table :jobs do |t|
          t.integer :cader_id
          t.index :cader_id
        end
      end
    end
    

提交回复
热议问题