3405
MySQLERRORNotableForeign KeysHIGH confidence

Cannot change foreign key child column (alternate path)

Production Risk

Low — DDL fails; no data is modified.

How to reproduce
trigger — this will error
trigger — this will error
ALTER TABLE child MODIFY COLUMN fk_col BIGINT;

expected output

ERROR 3405 (HY000): Cannot change column used in a foreign key constraint.

Fix

Drop FK, alter column, recreate FK

Drop FK, alter column, recreate FK
ALTER TABLE child DROP FOREIGN KEY fk_name; ALTER TABLE child MODIFY COLUMN fk_col BIGINT; ALTER TABLE child ADD FOREIGN KEY (fk_col) REFERENCES parent(id);

Why this works

Dropping the constraint before altering allows the column type change, then the constraint is recreated.

What not to do

Sources
Official documentation ↗

MySQL 8.0 — 3405 ER_FK_COLUMN_CANNOT_CHANGE_CHILD2

Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev

← All MySQL errors