Opened 4 weeks ago
Closed 10 days ago
#37224 closed Bug (fixed)
Migration questioner complains about missing defaults for fields in unmanaged models
| Reported by: | Jacob Walls | Owned by: | Vishy |
|---|---|---|---|
| Component: | Migrations | Version: | dev |
| Severity: | Release blocker | Keywords: | |
| Cc: | Sarah Boyce, Hanny G | Triage Stage: | Ready for checkin |
| Has patch: | yes | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description (last modified by )
Since the improvement to tracking unmanaged model field alterations in #35813, the migration questioner (the interactive prompt) will now complain on missing defaults for altered fields.
In a post-merge comment I suggested we could short-circuit in the questioner for unmanaged models, since if the model is unmanaged then it's not strictly true that it's "impossible" to add such fields, especially for unmanaged models that just shadow database views.
Sarah had a similar observation before merge.
With this patch, I no longer needed to enter dummy values in the prompt:
-
django/db/migrations/autodetector.py
diff --git a/django/db/migrations/autodetector.py b/django/db/migrations/autodetector.py index 0d0010f868..b9eff8ee2b 100644
a b class MigrationAutodetector: 1163 1163 or (field.blank and field.empty_strings_allowed) 1164 1164 or (isinstance(field, time_fields) and field.auto_now) 1165 1165 or (isinstance(field, auto_fields)) 1166 or not self.to_state.apps.get_model(app_label, model_name)._meta.managed 1166 1167 ) 1167 1168 if not preserve_default: 1168 1169 field = field.clone() … … class MigrationAutodetector: 1331 1332 and not new_field.has_default() 1332 1333 and not new_field.has_db_default() 1333 1334 and not new_field.many_to_many 1335 and self.to_state.apps.get_model(app_label, model_name)._meta.managed 1334 1336 ): 1335 1337 field = new_field.clone() 1336 1338 new_default = self.questioner.ask_not_null_alteration(
There would be a few other places to check to see where else we can short-circuit. What do folks think?
Change History (9)
comment:1 by , 4 weeks ago
| Description: | modified (diff) |
|---|
comment:2 by , 4 weeks ago
| Triage Stage: | Unreviewed → Accepted |
|---|
comment:3 by , 3 weeks ago
| Owner: | set to |
|---|---|
| Status: | new → assigned |
comment:4 by , 2 weeks ago
| Has patch: | set |
|---|
comment:5 by , 2 weeks ago
| Patch needs improvement: | set |
|---|
comment:6 by , 11 days ago
| Needs tests: | set |
|---|
comment:7 by , 10 days ago
| Needs tests: | unset |
|---|---|
| Patch needs improvement: | unset |
comment:8 by , 10 days ago
| Triage Stage: | Accepted → Ready for checkin |
|---|
Thank you!