blank=True vs null=True in Django
-
null=True
-
blank=True
- Validation layer.
- Model and form validation permit an empty value on save or submit.
- For strings, the actual value stored is
''
(empty string) unlessnull=True
is also set. - Has no effect on the SQL schema.
-
Common patterns
- String fields:
blank=True, null=False
→ empty string stored, forms omit value. - Non-string fields:
blank=True, null=True
→ databaseNULL
used, validation allows omission. - Mixing
null=True, blank=False
rarely useful—database allowsNULL
, but validation rejects empty input. - Leaving both as
False
enforces mandatory data at both database and validation levels.
- String fields:
-
Key distinctions
null
controls storage;blank
controls validation.- Database
NULL
≠ empty string; choose one to avoid ambiguity.