Deprecated NullBooleanField

NullBooleanField is deprecated and will be removed a future version of Django.

NullBooleanField is like BooleanField with null=True.

Historically the only values BooleanField accepted was True and False. BooleanField didn't permit null=True. If null was a valid value then NullBooleanField was used instead.

If our GitHub code review bot spots this issue in your pull request it gives this advice:

django-doctorbotsuggested changes just now
models.py
1
+
class CommentModel(models.Model):
2
+
    is_active = models.NullBooleanField()
Suggested changes
-
    is_active = models.NullBooleanField()
+
    is_active = models.BooleanField(null=True)
Commit suggestion

NullBooleanField is deprecated and will be removed a future version of Django.

Read more
3
+
    body = models.TextField()
Update models.py
We're your Django code review copilot. Get code improvements right in your pull request with our GitHub code review bot.

Configuring this check

Code Review Doctor will run this check by default. No configuration is needed but the check can be turned on/off using check code deprecated-nullboolean-field in your pyproject.toml file.

Read more about configuring Code Review Doctor.