gpt4 book ai didi

MySQL外键错误

转载 作者:太空宇宙 更新时间:2023-11-03 11:00:37 25 4
gpt4 key购买 nike

我正在尝试创建一个以 varchars 作为主键和外键的自连接表。该表已创建,但在尝试将数据插入表时我一直收到错误

表格

 CREATE TABLE `staff` (
`staff_id` VARCHAR(255) NOT NULL,
`name` VARCHAR(255) NULL DEFAULT NULL,
`email` VARCHAR(255) NULL DEFAULT NULL,
`manager_id` VARCHAR(255) DEFAULT NULL,
PRIMARY KEY (`staff_id`),
FOREIGN KEY (`manager_id`) REFERENCES `staff` (`staff_id`))

数据转储

   /*Data for the table `staff` */
INSERT INTO staff (STAFF_ID, NAME, EMAIL, MANAGER_ID)
VALUES ('lo1234', 'test','**.com', null);
INSERT INTO staff (STAFF_ID, NAME, EMAIL, MANAGER_ID)
VALUES ('er8909', 'test2','**.com', 'l01234');
INSERT INTO staff (STAFF_ID, NAME, EMAIL, MANAGER_ID)
VALUES ('ru6758', 'r**','**.com', 'l01234');
INSERT INTO staff (STAFF_ID, NAME, EMAIL, MANAGER_ID)
VALUES ('ad4567', 'admin','**.com', null);

架构的构造或插入的数据是否有问题?

最佳答案

1o1234 改为 1012345 这一行你错了,因为

INSERT INTO staff (STAFF_ID, NAME, EMAIL, MANAGER_ID)
VALUES ('lo1234', 'test','**.com', null);

将其更改为:

INSERT INTO staff (STAFF_ID, NAME, EMAIL, MANAGER_ID)
VALUES ('l01234', 'test','**.com', null);

关于MySQL外键错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16250805/

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