#31310: Wrong hint about recursive relationship -------------------------------------+------------------------------------- Reporter: Matheus | Owner: nobody Cunha Motta | Type: | Status: new Cleanup/optimization | Component: Database | Version: 3.0 layer (models, ORM) | Severity: Normal | Keywords: Triage Stage: | Has patch: 0 Unreviewed | Needs documentation: 0 | Needs tests: 0 Patch needs improvement: 0 | Easy pickings: 1 UI/UX: 0 | -------------------------------------+------------------------------------- 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. -- Ticket URL: <https://code.djangoproject.com/ticket/31310> 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 django-updates+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/056.f996317f736a339cdf1290c0e1a8e59f%40djangoproject.com.