﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
28545	unique_together does not handle null as most would expect it	Jimmy Merrild Krag	nobody	"If you are not well into databases, you may not realize that `NULL` is not the same as `NULL`, and therefore the below may seem like a good idea to ensure that you `SpaceShip` model can only have one currently active (not deleted) `Status`:

{{{
#!python
class SpaceShip(models.Model):
    ...

class Status(models.Model):
    paper = models.ForeignKey('SpaceShip', null=False, blank=False)

    created = models.DateTimeField(default=timezone.now, null=False, blank=False, editable=False)
    created_by = models.ForeignKey('auth.User', null=False, blank=False, editable=False)

    text = models.TextField(blank=False)

    deleted = models.DateTimeField(null=True, blank=True, editable=False)
    deleted_by = models.ForeignKey('auth.User', null=True, blank=True, editable=False)

    class Meta:
        ordering = ('created',)
        unique_together = ('paper', 'deleted')
}}}

People have handled this kind of scenario in the `clean` method of the model (most notably https://stackoverflow.com/a/4805581/1031534 which defines a super class for models where this is handled generally), but then you still have to override the save method to clean during save.

Perhaps Django should issue a warning when creating `unique_together` constraints, where one of the fields is null-able, or alternatively the constraint could be handled in Python."	Bug	closed	Core (System checks)	1.11	Normal	wontfix			Unreviewed	0	0	0	0	0	0
