1767
MySQLERRORNotableForeign KeysHIGH confidence
Cannot delete parent row — foreign key constraint
Production Risk
Medium — operation blocked; referential integrity maintained.
What this means
A DELETE on a parent table was blocked because child rows in another table still reference the parent key.
Why it happens
- 1Child rows exist that reference the parent row being deleted.
- 2The FK does not have ON DELETE CASCADE or ON DELETE SET NULL defined.
How to reproduce
trigger — this will error
trigger — this will error
DELETE FROM departments WHERE id = 5; -- employees reference dept 5
expected output
ERROR 1767 (23000): Cannot delete or update a parent row: a foreign key constraint fails.
Fix
Delete child rows first or add ON DELETE CASCADE to the FK
Delete child rows first or add ON DELETE CASCADE to the FK
DELETE FROM employees WHERE department_id = 5; DELETE FROM departments WHERE id = 5;
Why this works
Removes referencing rows before deleting the parent.
What not to do
✕
Sources
Official documentation ↗
MySQL 8.0 — 1767 ER_FK_CANNOT_DELETE_PARENT
Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev