我需要删除列上现有的外键约束,并添加一个同名的新约束,该约束引用另一个表的主键。
我收到一个错误的ERROR: Constraint type must be specified through options.type
。虽然我在option的对象中提供了约束类型作为第三个参数。
下面是供参考的迁移代码。
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;
}
}
转载请注明出处:http://www.jxbyjx.net/article/20230506/1057437.html