数据库MySQL查询错误

时间:2013-11-20 22:46:49

标签: mysql sql database

我正在尝试将语句插入到我的数据库中。以下是插入语句:

insert into advisor values ('00001', '11111');
insert into advisor values ('00002', '22222');
insert into advisor values ('00003', '33333');
insert into advisor values ('00004', '44444');
insert into advisor values ('00005', '55555');
insert into advisor values ('00006', '66666');
insert into advisor values ('00007', '77777');
insert into advisor values ('00008', '88888');
insert into advisor values ('00009', '99999');
insert into advisor values ('00010', '10101');"

我在这个问题上收到错误:

insert into advisor values ('00004', '44444');

出现此错误:

Error Code: 1452. Cannot add or update a child row: a foreign key constraint fails     (`university database`.`instructor`, CONSTRAINT instructor_ibfk_1 FOREIGN KEY (`department_name`) REFERENCES `department` (`department_name`) ON DELETE SET NULL)

任何人都可以对此错误提供任何知识吗?

谢谢!

1 个答案:

答案 0 :(得分:1)

错误是不言自明的。您输入的值必须首先存在于外键约束中的引用表中。

您还应该在INSERT语句中使用列列表。