Difference between ManyToOneRel and ForeignKey?
Question:
In django, what’s the difference between a ManyToOneRel and a ForeignKey field?
Answers:
ManyToOneRel
is not a django.db.models.fields.Field
, it is a class that is used inside Django but not in the user code.
Django relations model exposes (and documents) only OneToOneField, ForeignKey and ManyToManyField, which corresponds to the inner
- OneToOneField -> OneToOneRel
- ForeignKey -> ManyToOneRel
- ManyToManyField -> ManyToManyRel
See source of django.db.models.fields.related for further details.
In django, what’s the difference between a ManyToOneRel and a ForeignKey field?
ManyToOneRel
is not a django.db.models.fields.Field
, it is a class that is used inside Django but not in the user code.
Django relations model exposes (and documents) only OneToOneField, ForeignKey and ManyToManyField, which corresponds to the inner
- OneToOneField -> OneToOneRel
- ForeignKey -> ManyToOneRel
- ManyToManyField -> ManyToManyRel
See source of django.db.models.fields.related for further details.