gpt4 book ai didi

mysql - mysql 中的外键约束。我无法修复它吗?

转载 作者:行者123 更新时间:2023-11-29 12:19:03 25 4
gpt4 key购买 nike

我在mysql中创建了如下表:

CREATE TABLE employee (
fname varchar(15) not null,
minit varchar(1),
lname varchar(15) not null,
ssn char(9),
bdate date,
address varchar(50),
sex char,
salary decimal(10,2),
superssn char(9),
dno integer(4),
primary key (ssn),
foreign key (superssn) references employee(ssn)
);

然后我尝试插入以下信息:

INSERT INTO employee VALUES ("Bob","B","Bender","666666600",
"1968-04-17","8794 Garfield, Chicago, IL","M","96000.00","null","8");

不幸的是,我收到了这个错误:

Error Code: 1452. Cannot add or update a child row: a foreign key constraint 
fails (`test`.`employee`, CONSTRAINT `employee_ibfk_1` FOREIGN KEY
(`superssn`) REFERENCES `employee` (`ssn`))

我尝试更改表,使 superssn 可以为空,但没有解决方案有效。

ALTER TABLE employee MODIFY COLUMN superssn CHAR(9) default null;

最佳答案

"null"null 不同。删除引号。

关于mysql - mysql 中的外键约束。我无法修复它吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29320010/

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