Wednesday, April 7, 2021

Re: Unique and null

I'm not sure about the case with null. However, I believe that most uses of CharField leave null=False and use the empty string instead to represent "empty" value.

On April 7, 2021 1:06:44 AM CDT, Mike Dewhirst <miked@dewhirst.com.au> wrote:
I have just made a CharField unique and Django detects duplicates nicely 
but seems to ignore multiple instances where the field value is null.

    arn = models.CharField(
        max_length=MEDIUM,
        unique=True,
        null=True,
        blank=True,
    )

Is this correct behaviour?

Thanks

Mike


No comments:

Post a Comment