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
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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.