Fix ChangeField failure with index+column type changes on MySQL.
Review Request #14922 — Created March 17, 2026 and updated — Latest diff uploaded
When a
ChangeFieldmutation changes both the field type and
unique/db_indexattributes, MySQL'sMODIFY COLUMNruns before the
index is dropped. MySQL rejects this forTEXTorBLOBcolumns with
the error "BLOB/TEXT column used in key specification without a key
length".This happened because
ChangeField.mutate()returns early after
change_column_type()whenchange_column_type_sets_attrsisTrue
(MySQL), skipping thechange_column_attrs()call that handles index
drops.
change_column_type()now processesdb_index/uniquechanges from
new_attrswhenchange_column_type_sets_attrsisTrue, emitting
index drops as pre-SQL (before theMODIFY) and index adds as post-SQL
(after). The SQLite3 backend also calls the new helper to keep in-memory
database state in sync.
- Ran unit tests without the fix and verified that the new tests failed with
the same issue I saw in the wild. - Ran unit tests with the fix and verified that it was now fixed.
- Ran dbtests for mysql, sqlite, and postgresql.