This was probably a small mistake where the developer thought
ManyToManyField but typed ForeignKey instead. And the symmetrical=False is
an outdated requirement to recursive relationships, not applicable since
3.0. I'll provide a PR with a proposed correction shortly after.
--
Ticket URL: <https://code.djangoproject.com/ticket/31310>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
Comment (by Matheus Cunha Motta):
Here's a PR: https://github.com/django/django/pull/12497
--
Ticket URL: <https://code.djangoproject.com/ticket/31310#comment:1>
Old description:
> When there's more than 2 ForeignKeys pointing to the same model in an
> intermediary model of a m2m field and no through_fields have been set,
> Django will show an error with the following hint:
> {{{#!python
> hint=(
> 'If you want to create a recursive relationship, '
> 'use ForeignKey("%s", symmetrical=False, through="%s").'
> }}}
> But to create a recursive relationship the ManyToManyField should be used
> instead of ForeignKey. Also symmetrical=False should only be used with
> m2m fields, according to model field reference (link:
> https://docs.djangoproject.com/en/3.0/ref/models/fields/#django.db.models.ManyToManyField.symmetrical).
> And more than that, setting symmetrical=False is not required for
> recursive relationships since Django >= 3.0.
>
> This was probably a small mistake where the developer thought
> ManyToManyField but typed ForeignKey instead. And the symmetrical=False
> is an outdated requirement to recursive relationships, not applicable
> since 3.0. I'll provide a PR with a proposed correction shortly after.
New description:
When there's more than 2 ForeignKeys in an intermediary model of a m2m
field and no through_fields have been set, Django will show an error with
the following hint:
{{{#!python
hint=(
'If you want to create a recursive relationship, '
'use ForeignKey("%s", symmetrical=False, through="%s").'
}}}
But 'symmetrical' and 'through' are m2m keyword arguments, not ForeignKey.
This was probably a small mistake where the developer thought
ManyToManyField but typed ForeignKey instead. And the symmetrical=False is
an outdated requirement to recursive relationships with intermediary model
to self, not required since 3.0. I'll provide a PR with a proposed
correction shortly after.
Edit: fixed description.
--
--
Ticket URL: <https://code.djangoproject.com/ticket/31310#comment:2>
* has_patch: 0 => 1
* stage: Unreviewed => Accepted
--
Ticket URL: <https://code.djangoproject.com/ticket/31310#comment:3>
* owner: nobody => Matheus Cunha Motta
* status: new => assigned
* version: 3.0 => master
* needs_tests: 0 => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/31310#comment:4>
* needs_tests: 1 => 0
* stage: Accepted => Ready for checkin
--
Ticket URL: <https://code.djangoproject.com/ticket/31310#comment:5>
Comment (by Mariusz Felisiak <felisiak.mariusz@…>):
In [changeset:"308fab924195bdea2fc481e1466c3c3894c03400" 308fab92]:
{{{
#!CommitTicketReference repository=""
revision="308fab924195bdea2fc481e1466c3c3894c03400"
Refs #31310 -- Added test for check for using intermediate model with
ambiguous foreign key from model.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/31310#comment:6>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"e908eb62871f0b0aac63afa6601bf222bc2a1a7d" e908eb6]:
{{{
#!CommitTicketReference repository=""
revision="e908eb62871f0b0aac63afa6601bf222bc2a1a7d"
Fixed #31310 -- Fixed hints in checks for using intermediate model with
ambiguous foreign key.
symmetrical=False is not required since
87b1ad6e7351464c60e751b483d9dfce3a2d3382.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/31310#comment:7>