Django
Programming
Python
Web Development
Database Management

What is the difference between null=True and blank=True in Django?

System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design

Introduction

null=True and blank=True look similar in Django models, but they solve different problems. One controls whether the database column may store NULL, while the other controls whether validation allows the field to be empty in forms and model validation.

null=True Is About Database Storage

When you set null=True, Django allows the database column to store SQL NULL for that field.

python
1from django.db import models
2
3class Profile(models.Model):
4    nickname = models.CharField(max_length=50, null=True)
5    birth_date = models.DateField(null=True)

This means the database is allowed to record "no value" as NULL for those columns.

That setting matters most for database-level storage and for field types where an empty string is not a natural missing value, such as dates, numbers, and foreign keys.

blank=True Is About Validation

blank=True tells Django that the field is allowed to be empty during validation. That affects forms, admin, serializers that rely on model validation patterns, and Model.full_clean().

python
1from django.db import models
2
3class Profile(models.Model):
4    bio = models.TextField(blank=True)

With blank=True, a form can submit an empty value for bio without raising a validation error.

The key point is that blank=True does not by itself say how the value is stored in the database. It only changes whether Django treats the field as required at the validation layer.

Why Text Fields Are Special

For CharField and TextField, Django convention usually prefers empty strings over NULL. That is why many Django codebases use blank=True without null=True for text-based fields.

python
class Article(models.Model):
    subtitle = models.CharField(max_length=120, blank=True)

In this case, an empty subtitle is usually stored as "", not as NULL.

Using both null=True and blank=True on text fields can create two different representations of "no data": the empty string and NULL. That often makes querying and validation more confusing than necessary.

When to Use Both

For many non-text fields, both options are appropriate when the field is optional.

python
1class Event(models.Model):
2    starts_at = models.DateTimeField(null=True, blank=True)
3    organizer = models.ForeignKey(
4        "auth.User",
5        null=True,
6        blank=True,
7        on_delete=models.SET_NULL,
8    )

Here, null=True allows the database to store no value, and blank=True allows forms and admin to leave the field empty.

That pairing is common for dates, numbers, and relationships where an empty string is not a meaningful value.

Think About Queries and Semantics

Choosing between empty string and NULL is not just a syntax issue. It affects how you query the data.

python
Profile.objects.filter(bio="")
Profile.objects.filter(bio__isnull=True)

If a text field allows both empty strings and NULL, application code has to remember both cases. That is why Django projects usually standardize on one representation for missing text, and the common choice is the empty string with blank=True only.

Another practical rule is to keep form behavior and storage behavior aligned. If a field is optional in admin or forms but the database still requires a value, you create confusing validation paths where one layer says the field is optional and another says it is not.

Common Pitfalls

Assuming blank=True changes database nullability is incorrect. It changes validation, not the database column definition.

Adding both null=True and blank=True to text fields without a good reason often creates duplicate missing-value semantics.

For optional foreign keys or date fields, forgetting null=True can cause database-level errors even if forms allow blank input.

Summary

  • 'null=True controls whether the database may store SQL NULL.'
  • 'blank=True controls whether Django validation allows the field to be empty.'
  • For text fields, blank=True without null=True is usually the cleaner convention.
  • For dates, numbers, and foreign keys, optional fields often need both null=True and blank=True.

Related reading
Course
Beginner
27 lessons
10 hours
System Design Fundamentals

Build a strong foundation in designing scalable, reliable distributed systems.

View the course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design

All Rights Reserved.