From f09f90976d8fa8c2f9dd4725d3fe63c2f902b588 Mon Sep 17 00:00:00 2001 From: zhang1106 <849185023@qq.com> Date: Tue, 30 Dec 2025 13:34:15 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=95=B0=E6=8D=AE=E5=BA=93):=20=E5=9C=A8?= =?UTF-8?q?=E6=A8=A1=E5=9E=8B=E5=88=9D=E5=A7=8B=E5=8C=96=E6=97=B6=E5=A4=84?= =?UTF-8?q?=E7=90=86=E5=A4=96=E9=94=AE=E7=BA=A6=E6=9D=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 在同步数据库模型时临时禁用外键检查,避免因外键约束导致同步失败 --- backend/models/ticketIndex.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/backend/models/ticketIndex.js b/backend/models/ticketIndex.js index 5dc7cf5..939a7ae 100644 --- a/backend/models/ticketIndex.js +++ b/backend/models/ticketIndex.js @@ -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); } };