Blank char/text fields
|Reported by:||anonymous||Owned by:||jacob|
|Cc:||Triage Stage:||Ready for checkin|
|Has patch:||no||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
The documentation does a good job of pointing out that blank should be used for text/char fields instead of null. What wasn't totally clear is that for non-character based fields (e.g. Integer) you have to use blank=True for the validator to allow the field to be empty (e.g. when creating a new instance in Admin). Also, I would assume in this situation it substitutes NULL instead of an empty string, making it different from the char/text field case. Figured it'd be worth a mention.
The particular portion of the documentation can be found here:
"Note that empty string values will always get stored as empty strings, not as NULL — so use null=True for non-string fields such as integers, booleans and dates.
Avoid using null on string-based fields such as CharField and TextField unless you have an excellent reason. 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;” Django convention is to use the empty string, not NULL."
Change History (3)
Changed 9 years ago by SmileyChris
comment:1 Changed 9 years ago by SmileyChris
- Needs documentation unset
- Needs tests unset
- Patch needs improvement unset
- Triage Stage changed from Unreviewed to Ready for checkin