0
有没有办法在Rails 3.1+迁移中的字段上指定数据库级唯一性约束?我知道ActiveRecord的validates_uniqueness_of
会工作,但我很想知道这是否可以在其他地方指定。Rails 3.1+迁移中databse级别的独特模型字段?
例如,为了指定“登录”字段应该是在迁移,如独特的...
class CreateUsers < ActiveRecord::Migration
def change
create_table :users do |t|
t.string :name
t.string :login
t.timestamps
end
end
end
...我想补充一个选项一样:unique => true
。
Documentation中没有提到任何东西,所以我认为这不是一个很好的地方/做事情的方式,但有人知道如何实现它(即使它被手动添加到结果模式中)?或者是validates_uniqueness_的首选路线?
非常感谢,我给那后来去 – timecode