sequelize migration set unique constraint

Solutions on MaxInterview for sequelize migration set unique constraint by the best coders in the world

showing results for - "sequelize migration set unique constraint"
Fynn
29 Oct 2019
1// adding constraint while table creation
2queryInterface.createTable('Posts', {
3    title: {
4        type: Sequelize.STRING(200),
5    }
6}, {
7    uniqueKeys: {
8        Items_unique: {
9            fields: ['title']
10        }
11    }
12});
13
14// add constraint only
15queryInterface.addConstraint('Posts', ['title'], {
16  type: 'unique',
17  name: 'unique_constraint_name'
18});