#32351: AlterField migration on ForeignKey column fails on fresh DB when
referenced
model has been subsequently modified
-------------------------------------+-------------------------------------
Reporter: djangobugreport | Owner: nobody
Type: Bug | Status: closed
Component: Migrations | Version: 3.1
Severity: Normal | Resolution: invalid
Keywords: migration | Triage Stage:
AlterField ForeignKey default | Unreviewed
on_delete |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):
* cc: Simon Charette (added)
* status: new => closed
* resolution: => invalid
Comment:
Thanks for this report, however IMO it's not a supported to use callables
that create new objects in the
[https://docs.djangoproject.com/en/3.1/ref/models/fields/#default
Field.default]. Django evaluates `default` before applying a migration, in
your case there is a mismatch between model and table states. To avoid
this issue in the `RunPython()` operation you can get the model from the
versioned app registry, e.g. `apps.get_model("theapp", "Foo")`. I'm not
sure if it will work in the `Field.default`.
--
Ticket URL: <https://code.djangoproject.com/ticket/32351#comment:2>
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/073.15dc69ea07ccf9f9e7ba3000b2fe5dd6%40djangoproject.com.