Answers for "sequelize add unique constraint"

2

set unique true sequelize

key: {
    // needs to be unique
    type: DataTypes.UUID,
    allowNull: false,
    unique: true
}
Posted by: Guest on July-30-2020
0

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'
});
Posted by: Guest on April-21-2021

Browse Popular Code Answers by Language