简体   繁体   English

续集列的唯一约束

[英]Unique constraint on sequelize column

Using NodeJS and Sequelize 2.0, I'm writing a migration to create a new table. 使用NodeJS和Sequelize 2.0,我正在编写一个迁移来创建一个新表。 In addition to the primary key, I want to mark a second column to be enforced as unique. 除了主键之外,我还想将第二列标记为唯一。 I can't find anything about this in the documentation. 我在文档中找不到任何相关内容。

migration.createTable('data', {
    id: {
        type: DataTypes.INTEGER,
        primaryKey: true,
        autoIncrement: true
    },
    key: {
        // needs to be unique
        type: DataTypes.UUID,
        allowNull: false
    }
})
    .then(function () {
        done();
    });

The following works: 以下作品:

key: {
    // needs to be unique
    type: DataTypes.UUID,
    allowNull: false,
    unique: true
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM