MySQL 添加外键约束,不检查现有数据

mac2022-06-30  89

这可能是MySQL在InnoDB中设置了foreign key关联,造成无法更新或删除数据。可以通过设置FOREIGN_KEY_CHECKS变量来避免这种情况。

SET FOREIGN_KEY_CHECKS = 0;alter table Freight_Dispatcher_Country_Mapping add constraint FK_Reference_f4 foreign key (DispatcherID) references Freight_Dispatcher (ID) on delete restrict on update restrict;alter table Freight_Dispatcher_Culture add constraint FK_Reference_f3 foreign key (DispatcherID) references Freight_Dispatcher (ID) on delete restrict on update restrict;

SET FOREIGN_KEY_CHECKS = 1;

 

其他: 关闭唯一性校验 set unique_checks=0; set unique_checks=1;

转载于:https://www.cnblogs.com/qiyebao/p/4317547.html

相关资源:垃圾分类数据集及代码
最新回复(0)