【发布时间】:2014-10-19 01:26:02
【问题描述】:
我在 rails 中使用 shema_plus gem,我想这样做,所以如果两列的组合相同,我无法将数据复制到我的数据库中。
这不应该工作吗?:
t.string :name, null: false, index: { with: :deleted_at, unique: true }
':deleted_at' 绝对是我迁移中的一个字段。
但这允许我在 mysql 端输入两次相同的名称。
另外,这里是mysql给我的一些信息:
Index: index_plans_on_name_and_deleted_at
Definition:
Type BTREE
Unique Yes
Columns name
deleted_at
编辑_____________________________________________________
看起来我需要为 deleted_at 设置一个默认值,例如:
t.datetime :deleted_at, default: '2000-01-01'
【问题讨论】:
标签: ruby-on-rails schema