I am very confused about the usage of the OnetoOneField
. I thought it was for a case where a given record can only have 1 reference to another table. For example, a Child has 1 Parent.
But it seems that Django makes the field that is defined as OneToOne a primary key of your table, meaning it has a Unique constraint. This doesn’t make any sense. Any given Child has only 1 Parent. But there might be more than 1 child with the same parent. The the FK to the parent is not going to be unique in the entire Child table
I wanted to use OneToOne instead of ForeignKey in order to enforce the one-to-one aspect, as opposed to ForeignKey, which is 1 to Many (any given Child can have more than 1 parent).
Am I wrong in my understanding? Should I go back to using ForeignKey and just ensure that my code enforces 1-1?
I found these other links which asked the same question, but not sure that I saw a definitive answer
Why would someone set primary_key=True on an One to one reationship (OneToOneField)?
OneToOneField() vs ForeignKey() in Django