이 문서를 언급한 문서들1
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=Trueis 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→ databaseNULLused, validation allows omission. - Mixing
null=True, blank=Falserarely useful--database allowsNULL, but validation rejects empty input. - Leaving both as
Falseenforces mandatory data at both database and validation levels.
- String fields:
-
Key distinctions
nullcontrols storage;blankcontrols validation.- Database
NULL≠ empty string; choose one to avoid ambiguity.