续集“unique:true”使用不同的键名两次生成相同的唯一键
Test1:在电子邮件属性中添加“unique:true”。
Test2:在电子邮件属性中添加“unique:{args:true,msg:”xxxxxx“}”。
使用Sequelize:4.7.5和MySQL:5.7.19
我期待这两个testing用例都会有一个索引。
但是我得到了Test1的两个索引 。 两个索引具有相同的列但不同的键名 。
这是一个错误还是我做错了什么?
尝试下面的模型defs。
Test1 = { id: { type: Sequelize.INTEGER.UNSIGNED, primaryKey: true, autoIncrement: true }, emailId: { type: Sequelize.STRING, unique: true, allowNull: false, validate: { isEmail: { args: true, msg: 'Invalid email id.' } } } } Test2 = { id: { type: Sequelize.INTEGER.UNSIGNED, primaryKey: true, autoIncrement: true }, emailId: { type: Sequelize.STRING, unique: { args: true, msg: 'This email id is already registered.' }, allowNull: false, validate: { isEmail: { args: true, msg: 'Invalid email id.' } } } }
使用string来代替布尔值。
我在这里find了我的答案: https : //github.com/sequelize/sequelize/issues/6134
正常的索引与string