我想插入語句到我的數據庫。下面是插入語句:數據庫MySQL查詢錯誤
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)
誰能借給任何知識,這個錯誤?
謝謝!
部門表中的department_name應該包含值爲0004(或4444)的記錄,以引用的密鑰 – Habrashat
@JonathandeM爲準。 @HarshaBhat這個錯誤呢?這是什麼引用是不正確的?錯誤代碼:1452.無法添加或更新子行:外鍵約束失敗('大學數據庫'''結構',CONSTRAINT'instructs_ibfk_1' FOREIGN KEY('course_id','section_id','學期','year' )參考'section'('course_id','section_id','semester','year') – user2856210