Bogus foreign key constraint fail

前端 未结 9 1212
南笙
南笙 2020-11-28 01:52

I get this error message:

ERROR 1217 (23000) at line 40: Cannot delete or update a parent row: a foreign key constraint fails

<
相关标签:
9条回答
  • 2020-11-28 02:34

    Two possibilities:

    1. There is a table within another schema ("database" in mysql terminology) which has a FK reference
    2. The innodb internal data dictionary is out of sync with the mysql one.

    You can see which table it was (one of them, anyway) by doing a "SHOW ENGINE INNODB STATUS" after the drop fails.

    If it turns out to be the latter case, I'd dump and restore the whole server if you can.

    MySQL 5.1 and above will give you the name of the table with the FK in the error message.

    0 讨论(0)
  • 2020-11-28 02:35

    hopefully its work

    SET foreign_key_checks = 0; DROP TABLE table name; SET foreign_key_checks = 1;

    0 讨论(0)
  • 2020-11-28 02:36

    i found an easy solution, export the database, edit it what you want to edit in a text editor, then import it. Done

    0 讨论(0)
提交回复
热议问题