survi91 Posted February 3, 2012 Share Posted February 3, 2012 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 More sharing options...
MadTechie Posted February 3, 2012 Share Posted February 3, 2012 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 Link to comment https://forums.phpfreaks.com/topic/256300-problem-with-foreign-key/#findComment-1313881 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.