添加带索引的新列
要将新索引列 email
添加到 users
表,请运行以下命令:
rails generate migration AddEmailToUsers email:string:index
这将生成以下迁移:
class AddEmailToUsers < ActiveRecord::Migration[5.0]
def change
add_column :users, :email, :string
add_index :users, :email
end
end