gpt4 book ai didi

mysql - 不能在 mysql 中创建表,因为它们都相互依赖?

转载 作者:行者123 更新时间:2023-11-30 22:23:27 25 4
gpt4 key购买 nike

我有一个具有外键 RepID 的表 Supplier,另一个具有外键 SupplierID 的名为 Rep 的表。我该如何解决这个问题?如果我禁用外键检查,我会收到一条错误消息,指出在尝试添加数据时外键约束失败:

INSERT INTO Supplier VALUES
(44, "PENCO", "43", "Brown road", "Penville", "P14 5AA", "07816272182"),
(13, "PAPERCO", "1", "Old road", "Paperville", "P34 5NA", "07111232289"),
(24, "CALCCO", "12", "London road", "Calcville", "CA4 1XX", "07615282615"),
(8, "BAGCO", "10", "New road", "Bagville", "BA1 1AM", "07817827131");

INSERT INTO Item VALUES
(1, "Ballpoint pen", 1.00, "A nice pen", "~/Pictures/Pen", 20, 44),
(2, "Notepad", 3.20, "A nice notepad", "~/Pictures/Notepad", 21, 13),
(3, "Calculator", 4.50, "A nice calculator", "~/Pictures/Calculator", 22, 24),
(4, "Backpack", 10.00, "A nice backpack", "~/Pictures/Backpack", 23, 8);

INSERT INTO Rep VALUES
(41, "John", "Repman", "07019827336", 44, "JR@gmail.com", "JR@msn.com", "JRMAN", "1", "Potato street", "Patatoville", "P01 1FX"),
(11, "Fake", "Name", "07817001992", 13, "FN@gmail.com", "FN@msn.com", "FNMAN", "3", "Fake street", "Fakeville", "FA3 9KA"),
(1, "Good", "Name", "07911876678", 24, "GN@gmail.com", "GN@msn.com", "GNMAN", "12", "Good street", "Goodville", "GO0 1DD"),
(666, "John", "Smith", "07918822191", 8, "JS@gmail.com", "JS@msn.com", "JSMAN", "666", "Boring street", "Boringville", "BO1 1LM");

最佳答案

您可以禁用外键检查:

SET foreign_key_checks = 0;

CREATE TABLES ......;

SET foreign_key_checks = 1;

关于mysql - 不能在 mysql 中创建表,因为它们都相互依赖?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36036125/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com