#31416: FieldError when migrating field to new model subclass.
-------------------------------+------------------------------------
     Reporter:  Eduard Anghel  |                    Owner:  Nan Liu
         Type:  Bug            |                   Status:  assigned
    Component:  Migrations     |                  Version:  master
     Severity:  Normal         |               Resolution:
     Keywords:                 |             Triage Stage:  Accepted
    Has patch:  0              |      Needs documentation:  0
  Needs tests:  0              |  Patch needs improvement:  0
Easy pickings:  0              |                    UI/UX:  0
-------------------------------+------------------------------------

Comment (by Simon Charette):

 I think it should be doable to teach the auto-detector about generating
 these operations in the right order.

 I think the best approach would be to adjust `check_dependency` to account
 for this case. What's happening now is that created models detection runs
 before removed models one so while both operations depend on `Readable`
 model. It's possible that `generate_created_models` might need to be
 adjusted to add a dependency on field removal of all of its base to make
 sure the order is swapped. I think the correct dependency representation
 is `(base_app_label, base_model_name, field_name, False)` for all fields
 in all bases in
 
https://github.com/django/django/blob/6fbce45b0376f0ec8f3bf244f4f1f8d62c201f58/django/db/migrations/autodetector.py#L561-L565.

 Something the solution has to consider is when a field is removed from a
 base while two subclasses are added in the same run with this field (e.g.
 an extra `class Magazine(Readable): title =
 models.CharField(max_length=200)` would be added to the reporter's
 example). In this case a single `RemoveField` must be generated

-- 
Ticket URL: <https://code.djangoproject.com/ticket/31416#comment:6>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/070.c19a848bb18052bdec8868c6a4a49545%40djangoproject.com.

Reply via email to