#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 Adam (Chainz) Johnson):

 Hi @nanliu

 I believe the test for this should be in `test_autodetector.py`. The tests
 there don't create whole migrations. They make assertions on the output
 operations.

 Check out the test I wrote for a similar ticket in
 https://github.com/django/django/pull/12313/files#diff-
 c11e6432df7086eda3dfb9ab8e5b2839 , and those around that. They set up the
 before and after model states, ask the autodetector to find the operations
 through `get_changes()`, then make assertions on the operations.

 The "before" model states describe the state of the models before the
 change, which would be pulled from the migration history - in this case
 where just `Readable` exists. The "after" states describe the state the
 current model state, which would be pulled from the apps' model definitios
 - in this case, `Readable` with no fields and `Book` with the `title`
 field.

 When writing a test, please try use the predefined model states to reduce
 memory usage.

 Hope that helps you write a test. Once there's a failing test it should be
 easier to try find the fix.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/31416#comment:17>
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/070.4158597cea85976603fb535a2d68f385%40djangoproject.com.

Reply via email to