【问题标题】:Sequelize "unique: true" making same unique key two times with different keyname续集“唯一:真”两次使用不同的键名制作相同的唯一键
【发布时间】:2018-02-04 18:30:04
【问题描述】:

Test1:在电子邮件属性中添加“unique: true”。

Test2: 在 email 属性中添加“unique: {args: true, msg: "xxxxxx"}”。

使用 Sequelize:4.7.5 和 MySQL:5.7.19

我希望两个测试用例都有一个索引。

但我得到了 Test1 的 两个索引。两个索引都有相同的列但不同的键名。

这是一个错误还是我做错了什么?

尝试以下模型定义。

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.'
        }
    }
}
}

【问题讨论】:

    标签: mysql node.js sequelize.js


    【解决方案1】:

    使用字符串代替布尔值。

    我在这里找到了答案:https://github.com/sequelize/sequelize/issues/6134

    Normal index with string

    【讨论】:

    • 啊!!!!我错过了问题跟踪器中的列表。所以我是对的,它是一个错误。
    猜你喜欢
    • 1970-01-01
    • 2021-06-24
    • 1970-01-01
    • 2020-03-20
    • 2016-09-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多