Use Cases

  • null=True:

    Use this when you want Django to store NULL in the database for empty values. This is typically used for non-string fields like DateTimeField, ForeignKey, etc.
     

  • blank=True:

    Use this to allow empty input in Django forms. It’s required for user-facing interfaces where the field is optional.
     

  • Together:

    You usually use both when a field is truly optional:

note = models.CharField(max_length=100, null=True, blank=True)

Important Notes

  • For string-based fields (CharField, TextField), Django recommends:

    • Use blank=True only.

    • Avoid null=True, because Django stores empty strings ("") rather than NULLs.

    • This avoids having two “empty” values: NULL and "", which can lead to confusion.

Quick Example

class Profile(models.Model):
    bio = models.TextField(null=True, blank=True)  # A user can leave it blank in a form, and it’ll store NULL in the DB.
    age = models.IntegerField(null=True, blank=True)  # Can be omitted from the form and also be NULL in the DB.

Reference