ORM queries and Python code are made more complex because values will sometimes be None and other times str.

The null attribute specifies that the field can be None (null at database level). This is useful for optional fields.

This adds complexity as the data type is inconsistent: some instances may be strings and others None. This complicates ORM queries and extra code must guard against performing str operations on a NoneType.

This problem is avoided by specifying default='' instead. The database will even throw an exception if there is an attempt to explicitly save None, thus avoiding bad data.

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
+
    body = models.TextField(null=True)

ORM queries and Python code are made more complex because values will sometimes be None and other times str.

Read more
Suggested changes
-
    body = models.TextField(null=True)
+
    body = models.TextField(default="", blank=True)
Commit suggestion
3
+
    date = models.DateField()
Update models.py

Instantly check if you have this issue for free

    Works with tools you use

    Read about how it works.