(!) Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (
mowanj1_in605
.sportEvent
, CONSTRAINTsportEvent_ibfk_1
FOREIGN KEY (eventID
) REFERENCESevent
(eventID
))' in /home/mowanj1/public_html/Web2/Assignment1/createAthlete.html.php on line 222錯誤的(PK的和FK在正確的順序嘗試)(!) PDOException: SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (
mowanj1_in605
.sportEvent
, CONSTRAINTsportEvent_ibfk_1
FOREIGN KEY (eventID
) REFERENCESevent
(eventID
)) in /home/mowanj1/public_html/Web2/Assignment1/createAthlete.html.php on line 222
$createQuery = "CREATE TABLE sportEventMedal
sportEventMedalID INT NOT NULL AUTO_INCREMENT, sportEventID INT, medalID INT,
PRIMARY KEY (sportEventMedalID), FOREIGN KEY (sportEventID) REFERENCES sportEvent(sportEventID), FOREIGN KEY (medalID) REFERENCES medal(medalID)
$pdo->exec($createQuery);
while (! feof($file)) {
$temp = fgetcsv($file);
$insertQuery = "INSERT INTO sportEvent(eventID, sportID) VALUES('$temp[0]','$temp[1]')";
$pdo->exec($insertQuery);
}
fclose($file);
$的createQuery =「CREATE TABLE sportEventMedal – Nick
sportEventMedalID INT NOT NULL AUTO_INCREMENT, sportEventID INT, medalID INT, – Nick
PRIMARY KEY(sportEventMedalID), 外鍵(sportEventID)參考文獻sportEvent(sportEventID), 外鍵(medalID)參考獎牌(medalID) – Nick