0
我收到一個我完全不理解的錯誤。我想創建一個表,這裏是代碼:表錯誤:1452無法添加或更新子行:外鍵?
create table matricula.curso_estudiantes
(codigo varchar(8) NOT NULL,
studentid varchar(8) NOT NULL,
grade varchar(1) NOT NULL,
term numeric(5) NOT NULL,
PRIMARY KEY (codigo, studentid, term),
FOREIGN KEY (codigo)
REFERENCES curso(codigo),
FOREIGN KEY (studentid)
REFERENCES estudiantes(studentid));
insert into matricula.curso_estudiantes values
("COMP2120","X00101010","C",201010),
("COMP2315","X00101010","B",201030),
("COMP2120","X00121111","B",201030),
("COMP2315","X00121111","A",201030),
("COMP2120","X00121234","A",201130),
("COMP2900","X00101010","C",201110),
("COMP3850","X00101010","B",201110),
("COMP2900","X00121111","B",201130),
("COMP3850","X00121111","A",201130),
("COMP2315","X00121234","A",201130),
("COMP2400","X00101010","C",201210),
("MATH1500","X00101010","B",201210),
("COMP2400","X00121111","B",2),
("MATH1500","X00121111","A",2),
("COMP3850","X00121234","A",2),
("MATH1500","X00121234","W",2);
但我得到這個錯誤,而不是:
Error Code: constraint fails (
matricula
.curso_estudiantes
, CONSTRAINTcurso_estudiantes_ibfk_2
FOREIGN KEY (studentid
) REFERENCESestudiantes
(studentid
))
出了什麼問題?它創建表,但它給了我這個問題,沒有記錄插入到表中。哪個查詢解決了這個問題?我是mySQL的新手,所以我使用了很多教授的參考和例子。提前致謝。
我已經創建了兩個表格。一個給學生叫做「estudiantes」,另一個給「curso」的課程他們充滿了這個信息:http://i192.photobucket.com/albums/z30/FlameGhoul/Untitled.png http://i192.photobucket.com /albums/z30/FlameGhoul/Untitled1-1.png –
estudiantes表中的studentid列是否爲索引? –
此外,嘗試將問題分成幾部分:創建表格和插入記錄(首先嚐試一個)。 –