Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

sequelize migration set unique constraint

// adding constraint while table creation
queryInterface.createTable('Posts', {
    title: {
        type: Sequelize.STRING(200),
    }
}, {
    uniqueKeys: {
        Items_unique: {
            fields: ['title']
        }
    }
});

// add constraint only
queryInterface.addConstraint('Posts', ['title'], {
  type: 'unique',
  name: 'unique_constraint_name'
});
 
PREVIOUS NEXT
Tagged: #sequelize #migration #set #unique #constraint
ADD COMMENT
Topic
Name
9+7 =