Creating a foreign key in MySQL produces error:
Posted
by SnOrfus
on Stack Overflow
See other posts from Stack Overflow
or by SnOrfus
Published on 2010-06-08T22:07:03Z
Indexed on
2010/06/08
22:12 UTC
Read the original article
Hit count: 258
I'm trying to create a foreign key on a table in MySQL and I'm getting a strange error that there seems to be little info about in any of my searches.
I'm creating the key with this (emitted from mysql workbench 5.2):
ALTER TABLE `db`.`appointment`
ADD CONSTRAINT `FK_appointment_CancellationID`
FOREIGN KEY (`CancellationID` ) REFERENCES `db`.`appointment_cancellation` (`ID` )
ON DELETE NO ACTION
ON UPDATE NO ACTION
, ADD INDEX `FK_appointment_CancellationID` (`CancellationID` ASC) ;
at which point I get the error:
ERROR 1452: Cannot add or update a child row: a foreign key constraint fails (
alarmtekcore
., CONSTRAINTFK_lead_appointment_CancellationID
FOREIGN KEY (CancellationID
) REFERENCESlead_appointment_cancellation
(`)
I've checked here
but there's no data in the table.
© Stack Overflow or respective owner