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
Written by Yannis Jaquet
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Rails
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#