CREATE TABLE `TABLE1` ( `TABLE_ID1` varchar(4) NOT NULL, PRIMARY KEY (`TABLE_ID1`), ) ENGINE=MyISAM DEFAULT CHARSET=latin1; CREATE TABLE `TABLE2` ( `LOCAL_CUST_ID` int(10) NOT NULL, `TABLE_ID1` varchar(4) NOT NULL, ) ENGINE=InnoDB DEFAULT CHARSET=latin1; Both table created successfully in MySql but while trying adding foreign key by below Alter statement then getting below issue.
ALTER TABLE TABLE2 ADD CONSTRAINT FK_ID FOREIGN KEY(TABLE_ID1) REFERENCES TABLE1(TABLE_ID1); Error Code: 1452 Cannot add or update a child row: a foreign key constraint fails (`#sql-7fcd_79`, CONSTRAINT `FK_ID` FOREIGN KEY (`TABLE_ID1`) REFERENCES `TABLE1` (`TABLE_ID1`)) In both table I have used different engine.
Can someone please help what I am not able to add foreign key?