Unable to add foreign key between two tables tables on fields signup (uid) and login (uid)

23 Views Asked by At

I can't add foreign key between the tables on fields signup and login because of getting error:

#1452 - Cannot add or update a child row:
a foreign key constraint fails
(`cems`.`#sql-109c_1ab`, CONSTRAINT `#sql-109c_1ab_ibfk_1` FOREIGN KEY (`uid`) REFERENCES `login` (`uid`) ON DELETE CASCADE ON UPDATE CASCADE)
1

There are 1 best solutions below

0
Rajkumar On

The error comes when you are trying to add a row for which no matching row in in the other table.

The FOREIGN KEY clause is specified in the child table.

INSERT or UPDATE operation that attempts to create a foreign key value in a child table if there is no a matching candidate key value in the parent table it will reject