Monday, September 30, 2013

Re: Using unique_together with foreign key fields which may be None

On Mon, Sep 30, 2013 at 4:55 PM, Berndt Jung <berndt@brkt.com> wrote:
Because the lookup_value of a null field is None, the validation check is aborted entirely.  This seems wrong to me, and I'm wondering if I'm doing something wrong here.  Redefining the models is not something I can do at this point.

None in Python corresponds to NULL in SQL. SQL defines that NULL != NULL. So when checking for unique values the database will not consider two NULLs to be the same value; the NULLs will be considered to be different and will not violate the unique constraint. The Django code is doing the same check for uniquess that the database will be enforcing. There is no way I know of to make a database enforce uniqueness among NULL values...


--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CACS9raekOZyHHmjEuNRCH-JC9xL7qFqCTuYJbu55pCuONHw-oA%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.

No comments:

Post a Comment