Keep null as default againt Null boolean field

How to use NullBooleanFieldin models Djangowith SQLlite3, I want to keep the nulldefault value for the field nullBoolean, how to do it?

I migrated db from BooleanFieldto NullBooleanField, but still saves False as the default value.

Use in code:

LOCATOR_YES_NO_CHOICES = ((None,''), (True,'Yes'), (False, 'No'))
employed = models.NullBooleanField(choices=LOCATOR_YES_NO_CHOICES,
                                max_length=3,
                                blank=True, null=True, default="",)

Any example would be helpful.

+4
source share
1 answer

The empty string is ""notNone

>>> "" is None
False

If you want the default value None, then write:

employed = models.NullBooleanField(choices=LOCATOR_YES_NO_CHOICES,
                                max_length=3,
                                blank=True, null=True, default=None,)
+8
source

Source: https://habr.com/ru/post/1525561/


All Articles