On Friday, April 29, 2016 at 12:51:31 AM UTC-7, Florian Apolloner wrote:
>
>
> I am not against a note in the docs, but I find the fact that nulls are 
> not "unique" and can exist in an index more than once very useful (fwiw 
> ordering after a column with null can also be interesting across 
> databases). I'd be interested to hear about your use case -- the "general" 
> use case is usually that you have an optional column but want to ensure it 
> is unique as soon as it is filled…
>
>
Let's see if I can explain my use case without having to explain my whole 
domain ... 

I have a Model where it has a boolean field, "BOO".  When "BOO" is False, 
another field "VAL" should have a meaningful value, otherwise NULL.  VAL is 
the only nullable field.  (And yes, the boolean is actually superfluous, 
"VAL" is sufficient for the logic.)

I want the PK of the Model to always be unique combined with BOO=False and 
VAL (and a couple of other non-nullables).  But I also don't want duplicate 
values of PK,BOO=True,VAL=null, which I am currently getting.  Put another 
way, only one row should have PK,Boo=True for each PK, but I can have many 
PK,Bool=False

I see now that I need to provide a sentinel value -- 
BOO=True,VAL=<sentinel>, or manually create additional unique indexes.

Since it is conceivable for Django to create the right indexes to handle 
the null case, it would be nice to somehow be able to explicitly ask for 
what I want expressed in Django.  (unique_together obviously can't change 
its current default behavior.)

Is that helpful?

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-developers+unsubscr...@googlegroups.com.
To post to this group, send email to django-developers@googlegroups.com.
Visit this group at https://groups.google.com/group/django-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/75e8e4ca-528d-4cce-8072-30f69a5d58f8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to