Last Updated: February 25, 2016
·
1.176K
· yannis

Ruby on Rails: Directly add an index to a column when generating a migration

Typing this in your terminal

rails generate migration add_user_id_to_items user_id:integer:index

will generate

class AddUserIdToItems < ActiveRecord::Migration
    def change
        add_column :items, :user_id, :integer
        add_index :items, :user_id
    end
end