Jump to content

Problem with Foreign Key,


survi91

Recommended Posts

Hi,

 

I'm having following problem when I try to add records in two tables, one (password) has primary key and student has a foreign key contraint with password.

 

Anyone please clarify what Im doing wrong.

 

Thanks !

 

SQL CODE:

 

INSERT INTO student(id, firstname, surname,dob, class,nationality,houseno,line1,line2,city)

  VALUES('00010', 'test','test','1980-01-01','test','test','test','test','test','test');

 

INSERT INTO password (id, password,salt)

  VALUES('00010','abc','abcde');

 

ERROR:

#1452 - Cannot add or update a child row: a foreign key constraint fails (`chr_fyp/student`, CONSTRAINT `student_ibfk_1` FOREIGN KEY (`id`) REFERENCES `password` (`id`) ON DELETE CASCADE ON UPDATE CASCADE)

Link to comment
https://forums.phpfreaks.com/topic/256300-problem-with-foreign-key/
Share on other sites

i Believe that

INSERT INTO password (id, password,salt) VALUES('00010','abc','abcde');

fails because the User with that foreign key doesn't exist,

is the ID really 00010 ? or 10 ?

 

Try entering the students details and confirm they are in the database, then try the password

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.