#32351: AlterField migration on ForeignKey column fails on fresh DB when
referenced
model has been subsequently modified
-------------------------------------+-------------------------------------
Reporter: djangobugreport | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 3.1
Severity: Normal | Resolution:
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 djangobugreport):
* severity: Release blocker => Normal
Comment:
After some more tinkering I've found the following work around:
1. Modify the "default" argument of the models.ForeignKey call in the
second generated migration to be some invalid ID value, like -1:
{{{
field=models.ForeignKey(default=TheApp.models.get_default_foo,
on_delete=django.db.models.deletion.SET_DEFAULT, to='TheApp.foo'),
# change to
field=models.ForeignKey(default=-1,
on_delete=django.db.models.deletion.SET_DEFAULT, to='TheApp.foo'),
}}}
2. Generate a new fourth migration, which will run after the "piyo" field
has been added, and change the "default" setting back to the callback
function.
This works for me although it will have to be done again every time the
model Foo changes.
I have also changed the level of this ticket to Normal since I noticed
your FAQ states that "Release blocker" is for things blocking a release of
Django (I had assumed it was for things blocking the release of user
projects).
--
Ticket URL: <https://code.djangoproject.com/ticket/32351#comment:1>
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.cd59fb27912be2ccceecc52dafa2a364%40djangoproject.com.