rails generate migration add_user_id_to_pins user_id:integer:index
This Indicates that you have PIN model and you want to add extra attribute named user_id to pins.
I think you have relation between pin and user. like either
user has_many pins
pin belongs_to user
or
user has_one pin
pin belongs_to user
right command to run migration is
rails g migration add_user_id_to_pins user_id:integer
user_id : field name
Integer : Type that you assigned to user_id.
Stores only id of the user.
def change
add_column :pins, :user_id, :integer
end
This is what you can see in migration file.
You have added index wrong way. like you can add index manually. after generation migration file go to that migration and add
add_index :pins, :user_id
For ActiveRecord Migration : http://guides.rubyonrails.org/migrations.html For Index In rails refer this : https://tomafro.net/2009/08/using-indexes-in-rails-index-your-associations
Hope you can understand what is migration and what/why index.