MySQL - Cannot add or update a child row: a foreign key constraint fails

后端 未结 9 640
执念已碎
执念已碎 2021-01-07 19:25

This seems to be a common error, but for the life of me I can\'t figure this out.

I have a set of InnoDB user tables in MySQL that are tied together via foreign key;

9条回答
  •  执念已碎
    2021-01-07 19:56

    I've faced this issue and the solution was making sure that all the data from the child field are matching the parent field

    for example, you want to add foreign key inside (attendance) table to the column (employeeName)

    where the parent is (employees) table, (employeeName) column

    all the data in attendance.employeeName must be matching employee.employeeName

提交回复
热议问题