For the complete documentation index, see llms.txt. This page is also available as Markdown.

Error 1833: Cannot change column: used in a foreign key constraint of table

Error Code
SQLSTATE
Error
Description

1833

HY000

ER_FK_COLUMN_CANNOT_CHANGE_CHILD

Cannot change column '%s': used in a foreign key constraint '%s' of table '%s'

Possible Causes and Solutions

An ALTER TABLE statement tried to change a column that another table references through a foreign key, in a way that would change how its values compare with the referencing column. Changing the column's type, length, character set, or collation all qualify. A common case is converting a table to a different collation, where the referencing table still uses the old one. The third name in the message is the table holding the constraint.

Setting foreign_key_checks to 0 does not lift this restriction, and neither does choosing a different ALGORITHM.

A referencing table's constraint cannot be dropped from within the referenced table's ALTER TABLE statement, so drop it on the referencing table first, then apply the change to both tables and re-create the constraint. For the full procedure, see Changing the Character Set or Collation of a Foreign Key Column.

If the table being altered is the one holding the constraint, the server reports error 1832 instead.

This page is licensed: CC BY-SA / Gnu FDL

spinner

Last updated

Was this helpful?