#33595: Check Constraint on nullable BooleanField should not be simplified
-------------------------------------+-------------------------------------
     Reporter:  Peter Law            |                    Owner:  nobody
         Type:  Bug                  |                   Status:  closed
    Component:  Database layer       |                  Version:  3.2
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:  invalid
     Keywords:                       |             Triage Stage:
                                     |  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

 * status:  new => closed
 * resolution:   => invalid


Comment:

 Thanks for this ticket, however that's how a `CHECK` constraints works in
 all databases and that's why not-null constraints exist, see for example
 PostgreSQL [https://www.postgresql.org/docs/current/ddl-constraints.html
 docs]:
 > ''"It should be noted that a check constraint is satisfied if the check
 expression evaluates to true or the null value. Since most expressions
 will evaluate to the null value if any operand is null, they will not
 prevent null values in the constrained columns. To ensure that a column
 does not contain null values, the not-null constraint described in the
 next section can be used."''

 Switching to `"it_exists" = TRUE` wouldn't change this behavior. You
 should use `models.BooleanField(null=False)` or explicitly add `__isnull`
 to `check=models.Q(it_exists=True, is_exists__isnull=False)`.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/33595#comment:1>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/0107017fb5dc2f5e-79fd2992-6994-449c-95a6-3a221b184c36-000000%40eu-central-1.amazonses.com.

Reply via email to