#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 Nan Liu):
Replying to [comment:17 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.
So, my code should be correct by using `self.get_changes([Readable],
[Readable with no fields, Book, Magazine])`. but my code meant to fix this
issue wasn't executed when I use `self.get_changes` while doing two
separate migrations will execute my added code, which is confusing. Also I
suspect that the first migration will construct a `loader.graph` that will
reorder the action operations.
--
Ticket URL: <https://code.djangoproject.com/ticket/31416#comment:18>
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.13c67a4800ee20d5cdcdaabccc907901%40djangoproject.com.