Avoid using `null` on string-based fields such as CharField and TextField

Python pattern

Avoid using null on string-based fields such as CharField and TextField. If a string-based field has null=True, that means it has two possible values for no data: NULL, and the empty string. In most cases, it's redundant to have two possible values for "no data" the Django convention is to use the empty string, not NULL.


Apply with the Grit CLI
grit apply no_null_string_field

Model with null=True

BEFORE
from django.db import models
from django.db.models import Model

class FakeModel(Model):
    fieldOne = models.CharField(
        max_length=200,
        null=True)
AFTER
from django.db import models
from django.db.models import Model

class FakeModel(Model):
    fieldOne = models.CharField(
        max_length=200,
        blank=True)

Model with null=True and blank=True

BEFORE
fieldThree = models.CharField(
        unique=True,
        null=True,
        blank=True,
        max_length=100
    )
AFTER
fieldThree = models.CharField(
        unique=True,

        blank=True,
        max_length=100
    )

Model without null=True and blank=True

PYTHON
notText = models.IntegerField(
        max_value=255
    )