fix(数据库): 在模型初始化时处理外键约束

在同步数据库模型时临时禁用外键检查,避免因外键约束导致同步失败
This commit is contained in:
zhang1106
2025-12-30 13:34:15 +08:00
parent 9b72289a2f
commit f09f90976d
+3
View File
@@ -163,7 +163,9 @@ const initAssociations = () => {
const initializeModels = async () => {
try {
await sequelize.query('SET FOREIGN_KEY_CHECKS = 0');
await sequelize.sync({ alter: true });
await sequelize.query('SET FOREIGN_KEY_CHECKS = 1');
console.log('工单相关数据表同步完成');
initAssociations();
@@ -171,6 +173,7 @@ const initializeModels = async () => {
console.log('工单系统数据初始化完成');
} catch (error) {
await sequelize.query('SET FOREIGN_KEY_CHECKS = 1');
console.error('初始化工单系统数据失败:', error);
}
};