Hello All,

In http://code.djangoproject.com/browser/django/trunk/django/forms/models.py
line 53 it states:

53              # OneToOneField doesn't allow assignment of None. Guard
against that
54              # instead of allowing it and throwing an error.
55              if isinstance(f, models.OneToOneField) and cleaned_data
[f.name] is None:
56                  continue

Can someone please explain why a OneToOneField cannot be null? Surely
if null=True there are no issues with assigning NULL to which is
essentially a FK.

Further reading of the function SingleRelatedObjectDescriptor which
seems to implement most of the OTOF functionality actually states:

http://code.djangoproject.com/browser/django/trunk/django/db/models/fields/related.py

207             # If null=True, we can assign null here, but otherwise
the value needs
208             # to be an instance of the related class.
209             if value is None and self.related.field.null == False:

Thank you,

Kieran

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.


Reply via email to