I need to remove the existing foreign key constraint on a column and add a new constraint with same name which refers to primary key of another table.
I am getting an error ERROR: Constraint type must be specified through options.type
. Though I am providing constraint type in option's object as third parameter.
Below is the migration code for reference.
async up(queryInterface, Sequelize){
const transaction = await queryInterface.sequelize.transaction();
try {
await queryInterface.removeConstraint(
'shipments',
'shipments_status_id_fkey',
{ transaction }
);
await queryInterface.addConstraint(
'shipments',
'status_id',
{
type: 'foreign key',
name: 'shipments_status_id_fkey',
references: {
table: 'statuses',
field: 'id'
},
transaction
}
);
await transaction.commit();
} catch (err) {
await transaction.rollback();
throw err;
}
}