Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unique constraint on sequelize column

Using NodeJS and Sequelize 2.0, I'm writing a migration to create a new table. 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();     }); 
like image 909
Jeff Fairley Avatar asked Jan 23 '15 18:01

Jeff Fairley


1 Answers

The following works:

key: {     // needs to be unique     type: DataTypes.UUID,     allowNull: false,     unique: true } 
like image 130
Yuri Zarubin Avatar answered Sep 28 '22 01:09

Yuri Zarubin