tags:

views:

45

answers:

1

Query:

INSERT INTO `job_listing_has_employer_details` (`job_listing_id`, `employer_details_id`)
VALUES (6, '5')

Error:

Cannot add or update a child row: a foreign key constraint fails (mydb.job_listing_has_employer_details, CONSTRAINT job_listing_has_employer_details_ibfk_2 FOREIGN KEY (employer_details_id) REFERENCES employer_details (id))

What does this mean? The two ID's I am inserting into the table exist.

+1  A: 

It means it can't find '5' in the id column of the employer_details table. If there is a 5 in that column of that table, then maybe the data is numeric, so must be passed without quotes. If so, try:

INSERT INTO `job_listing_has_employer_details` (`job_listing_id`, `employer_details_id`) VALUES (6, 5) 
RedFilter
I am casting the value into an int with PHP and I am still getting said error
sea_1987
What is the output of `select count(*) from employer_details where id = 6`?
RedFilter
6 is the job_listing_id not the employer_details_id
sea_1987
@sea: Oops, I meant 5.
RedFilter
So, let's try again. What is the output of `select count(*) from employer_details where id = 5`?
RedFilter