MySQL 添加外键约束,不检查现有数据
这可能是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;