PHP PDO - Inserting into table with foreign keys


I want to insert into a table called Festivals that has two foreign keys (venueID & ticketID).

The SQL:

$addFestivalSql = "INSERT INTO festivals 
                        VALUES(DEFAULT, :festivalName, :festivalDescription, 
                                :festivalImage, :festivalLineup, 
                                :musicTypeId, DEFAULT,  DEFAULT)";  

The error:

Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails

The Festivals Table:

The Festivals Table

enter image description here

I've created the two foreign key constraints with venueID and ticketID relating to the two primary keys.

Why do you think I'm getting this error?


Show source
| pdo   | php   | mysql   | sql   | phpmyadmin   2017-01-05 18:01 0 Answers

Answers ( 0 )

◀ Go back