Re: foreign key with unique versus one-to-one
On Thu, Apr 4, 2013 at 1:01 PM, Mike Dewhirst <miked@dewhirst.com.au> wrote:
-- I have noticed that there appears to be no difference in Postgres between a OneToOneField and a ForeignKey with unique=True
Is there any/much difference in Django?
At a database level - no. The implementation is identical, to the extent that OneToOneField is a subclass of ForeignKey that forces unique=True.
At an API level, there is one very small difference. The default reverse accessor for a Foreign Key will be named '<object name>_set', and it will return a QuerySet. The default reverse accessor for a OneToOne Key will be named '<object name>', and it will return a single object.
Yours,
Russ Magee %-)
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home