#1452 - Cannot add or update a child row: a foreign key constraint fails (`Appian`.`#sql-alter-34ce-15086d9`, CONSTRAINT `table1_ibfk_2` FOREIGN KEY (`first_id`) REFERENCES `table2` (`first_id`))
What does this error mean?
Discussion posts and replies are publicly visible
Hi Shubha, You can find the rows present in the child table that is causing the conflict while establishing the foreign key constraint by using the below query:(Please change the table name and column name according to your scenario)SELECT * FROM childTable WHERE childTablePrimaryKey IN (SELECT childTablePrimaryKey from childTable WHERE NOT EXISTS (Select 1 from parentTable where parentTable.foreignkeyColumn = childTable.foreignkeyColumn) ) AND foreignkeyColumn IS NOT NULL;The result of above query will give you the conflicting rows and please try deleting those rows and then execute the foreign key creation query.