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

Error 1832: Cannot change column: used in a foreign key constraint

Error Code
SQLSTATE
Error
Description

1832

HY000

ER_FK_COLUMN_CANNOT_CHANGE

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

Possible Causes and Solutions

An ALTER TABLE statement tried to change a column that the table uses as a foreign key, in a way that would change how its values compare with the referenced 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 referenced table still uses the old one.

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

To make the change, drop the constraint in the same ALTER TABLE statement as the column change, apply the matching change to the referenced table, then re-create the constraint. For the full procedure, see Changing the Character Set or Collation of a Foreign Key Column.

If the referenced table is the one being altered, the server reports error 1833 instead.

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

spinner

Last updated

Was this helpful?