diff options
| author | Jon Dufresne <jon.dufresne@gmail.com> | 2016-05-18 07:30:42 -0700 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2016-06-13 09:14:36 -0400 |
| commit | 267dc4adddd2882182f71a7f285a06b1d4b15af0 (patch) | |
| tree | 085fbeac6fa9139c5214bc16b46535cde690733d /docs/ref/models | |
| parent | f2c0eb19e961f5864573251e70bdcdecd0250aed (diff) | |
Fixed #4136 -- Made ModelForm save empty values for nullable CharFields as NULL.
Previously, empty values were saved as strings.
Diffstat (limited to 'docs/ref/models')
| -rw-r--r-- | docs/ref/models/fields.txt | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/docs/ref/models/fields.txt b/docs/ref/models/fields.txt index a56c445c31..2435201db8 100644 --- a/docs/ref/models/fields.txt +++ b/docs/ref/models/fields.txt @@ -43,11 +43,13 @@ If ``True``, Django will store empty values as ``NULL`` in the database. Default is ``False``. Avoid using :attr:`~Field.null` on string-based fields such as -:class:`CharField` and :class:`TextField` because empty string values will -always be stored as empty strings, not as ``NULL``. If a string-based field has +:class:`CharField` and :class:`TextField`. 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;" the Django convention is to use the empty string, not ``NULL``. +for "no data;" the Django convention is to use the empty string, not +``NULL``. One exception is when a :class:`CharField` has both ``unique=True`` +and ``blank=True`` set. In this situation, ``null=True`` is required to avoid +unique constraint violations when saving multiple objects with blank values. For both string-based and non-string-based fields, you will also need to set ``blank=True`` if you wish to permit empty values in forms, as the |
