向表中添加唯一列
要向 users
添加新的唯一列 email
,请运行以下命令:
rails generate migration AddEmailToUsers email:string:uniq
这将创建以下迁移:
class AddEmailToUsers < ActiveRecord::Migration[5.0]
def change
add_column :users, :email, :string
add_index :users, :email, unique: true
end
end