Opened 3 days ago
Last modified 42 hours ago
#37224 assigned Bug
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: | Accepted |
| Has patch: | no | 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 (3)
comment:1 by , 3 days ago
| Description: | modified (diff) |
|---|
comment:2 by , 3 days ago
| Triage Stage: | Unreviewed → Accepted |
|---|
comment:3 by , 42 hours ago
| Owner: | set to |
|---|---|
| Status: | new → assigned |
Thank you!