Suppose I created a table table
in a Rails app. Some time later, I add a column running:
rails generate migration AddUser_idColumnToTable user_id:string.
Then I realize I need to add user_id
as an index. I know about the add_index
method, but where should this method be called? Am I supposed to run a migration (if yes, which one ?), then adding by hand this method?
You can run another migration, just for the index:
class AddIndexToTable < ActiveRecord::Migration
def change
add_index :table, :user_id
end
end