I'm learning mysql and I try to create 2 tables which name student and course and column idnumber from student table and std_id from course table is foreign key.But when I want insert data to each of table,I got "error 1452<23000>cannot add or update a child row". These are my tables: student:
CREATE TABLE student(
name VARCHAR(20) NOT NULL,
idnumber INT(3) NOT NULL,
email VARCHAR(50) NOT NULL,
phone INT(10) NOT NULL,
PRIMARY KEY (idnumber));
CREATE TABLE course(
course_id INT(5) NOT NULL,
std_id INT(3) NOT NULL,
std_name VARCHAR(20) NOT NULL,
course_name VARCHAR(40) NOT NULL,
score INT(2) NOT NULL,
PRIMARY KEY (course_id),
FOREIGN KEY (std_id) REFERENCES student(idnumber));
ALTER TABLE student
ADD FOREIGN KEY (idnumber)
REFERENCES course(std_id);
this is my code in mysql.I am be grateful if someone help me.
I'm apologize for my bad English.