Mysql error 1452 - Cannot add or update a child row: a foreign key constraint fails

前端 未结 21 2279
生来不讨喜
生来不讨喜 2020-11-22 01:32

I\'m having a bit of a strange problem. I\'m trying to add a foreign key to one table that references another, but it is failing for some reason. With my limited knowledge o

21条回答
  •  长情又很酷
    2020-11-22 02:25

    It seems there is some invalid value for the column line 0 that is not a valid foreign key so MySQL cannot set a foreign key constraint for it.

    You can follow these steps:

    1. Drop the column which you have tried to set FK constraint for.

    2. Add it again and set its default value as NULL.

    3. Try to set a foreign key constraint for it again.

提交回复
热议问题