--
Ticket URL: <https://code.djangoproject.com/ticket/27903>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
Old description:
> When you create a ForeignKey with a related_name='+' to a second model,
> and you rename the second model, the model which is referred in the
> ForeignKey is not updated. I've created a updated
> OperationTests.test_rename_model test to show this (I'll update this
> ticket when I've created the PR). This only affects 1.10, this issue
> seems to be fixed in 1.11.
New description:
When you create a ForeignKey with a related_name='+' to a second model,
and you rename the second model, the model which is referred in the
ForeignKey is not updated. I've created a updated
OperationTests.test_rename_model test to show this (PR:
https://github.com/django/django/pull/8146). This only affects 1.10, this
issue seems to be fixed in 1.11.
--
--
Ticket URL: <https://code.djangoproject.com/ticket/27903#comment:1>
* component: Uncategorized => Migrations
Comment:
I assume this was fixed by the `RenameModel` refactor in #27310 as we
don't rely on ''related objects'' anymore (which can be missing when
`related_name` ends with `'+'`).
I'm not sure this is worth fixing at this point in the 1.10 release cycle.
--
Ticket URL: <https://code.djangoproject.com/ticket/27903#comment:2>
* status: new => closed
* resolution: => fixed
Comment:
I agree with Simon.
--
Ticket URL: <https://code.djangoproject.com/ticket/27903#comment:3>
Comment (by Alexander Schrijver):
As a workaround you can do is: before the RenameModel with a AlterField
set the ForeignKey's related_name to some temporary value, and then set it
back to '+' when you've done the RenameModel. e.g.:
{{{
migrations.AlterField(
model_name='SomeModel',
name='some_field',
field=models.ForeignKey(... related_name='xxx', to='app.OtherModel'),
),
migrations.RenameModel('OtherModel', 'OtherModel2'),
migrations.AlterField(
model_name='SomeModel',
name='some_field',
field=models.ForeignKey(... related_name='+', to='app.OtherModel2'),
),
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/27903#comment:4>