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 Jacob Walls)

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:  
    11631163            or (field.blank and field.empty_strings_allowed)
    11641164            or (isinstance(field, time_fields) and field.auto_now)
    11651165            or (isinstance(field, auto_fields))
     1166            or not self.to_state.apps.get_model(app_label, model_name)._meta.managed
    11661167        )
    11671168        if not preserve_default:
    11681169            field = field.clone()
    class MigrationAutodetector:  
    13311332                        and not new_field.has_default()
    13321333                        and not new_field.has_db_default()
    13331334                        and not new_field.many_to_many
     1335                        and self.to_state.apps.get_model(app_label, model_name)._meta.managed
    13341336                    ):
    13351337                        field = new_field.clone()
    13361338                        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 Jacob Walls, 4 weeks ago

Description: modified (diff)

comment:2 by Natalia Bidart, 4 weeks ago

Triage Stage: UnreviewedAccepted

Thank you!

comment:3 by Vishy, 3 weeks ago

Owner: set to Vishy
Status: newassigned

comment:4 by Vishy, 2 weeks ago

Has patch: set

comment:5 by Jacob Walls, 2 weeks ago

Patch needs improvement: set

comment:6 by Jacob Walls, 11 days ago

Needs tests: set

comment:7 by Vishy, 10 days ago

Needs tests: unset
Patch needs improvement: unset

comment:8 by Jacob Walls, 10 days ago

Triage Stage: AcceptedReady for checkin

comment:9 by Jacob Walls <jacobtylerwalls@…>, 10 days ago

Resolution: fixed
Status: assignedclosed

In 8f52e919:

Fixed #37224 -- Skipped questioner for field changes on unmanaged models.

Note: See TracTickets for help on using tickets.
Back to Top