#31310: Wrong hint about recursive relationship
-------------------------------------+-------------------------------------
Reporter: Matheus Cunha Motta | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: Database layer | Version: 3.0
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Description changed by Matheus Cunha Motta:
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>
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/071.ca5c4fd78ead29872cb4bae3581129a7%40djangoproject.com.