Opened 83 minutes ago
#37260 assigned Bug
AlterField changing only a Python-level on_delete option performs unnecessary DDL
| Reported by: | Adam Johnson | Owned by: | Adam Johnson |
|---|---|---|---|
| Component: | Database layer (models, ORM) | Version: | 6.1 |
| Severity: | Release blocker | Keywords: | |
| Cc: | Triage Stage: | Unreviewed | |
| Has patch: | yes | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
Database-level delete options, added in #21961, made an AlterField that changes only the Python-level on_delete option of a ForeignKey (e.g. CASCADE to PROTECT, or SET_NULL to CASCADE) execute real DDL. On most backends the foreign key constraint is dropped and recreated, and on SQLite the whole table is rebuilt. In 6.0 such migrations were database no-ops: the AlterField operation was generated for state, but BaseDatabaseSchemaEditor._field_should_be_altered() returned False, so previously-free migrations become expensive and locking after upgrading to 6.1.