commit 8756670d953c64bd2ae99915987678a487bb0f6f
Author: navneet suman <navneet35371@gmail.com>
Date: Tue Feb 25 21:14:46 2014 +0530
Clarify documentation on Field.blank and Field.null options #22145
diff --git a/docs/ref/models/fields.txt b/docs/ref/models/fields.txt
index cecfddc..076b0a0 100644
|
a
|
b
|
The following arguments are available to all field types. All are optional.
|
| 39 | 39 | If ``True``, Django will store empty values as ``NULL`` in the database. Default |
| 40 | 40 | is ``False``. |
| 41 | 41 | |
| 42 | | Note that empty string values will always get stored as empty strings, not as |
| 43 | | ``NULL``. Only use ``null=True`` for non-string fields such as integers, |
| 44 | | booleans and dates. For both types of fields, you will also need to set |
| | 42 | Avoid using :attr:`~Field.null` on string-based fields such as |
| | 43 | :class:`CharField` and :class:`TextField` because empty string values will always get |
| | 44 | stored as empty strings, not as ``NULL``. If a string-based field has ``null=True``, |
| | 45 | that means it has two possible values for "no data": ``NULL``, and the empty |
| | 46 | string. In most cases, it's redundant to have two possible values for "no data;" |
| | 47 | Django convention is to use the empty string, not ``NULL``. |
| | 48 | |
| | 49 | Note for both string-based and non-string-based fields, you will also need to set |
| 45 | 50 | ``blank=True`` if you wish to permit empty values in forms, as the |
| 46 | | :attr:`~Field.null` parameter only affects database storage (see |
| 47 | | :attr:`~Field.blank`). |
| | 51 | :attr:`~Field.null` parameter only affects database storage (see:attr:`~Field.blank`). |
| | 52 | |
| 48 | 53 | |
| 49 | | Avoid using :attr:`~Field.null` on string-based fields such as |
| 50 | | :class:`CharField` and :class:`TextField` unless you have an excellent reason. |
| 51 | | If a string-based field has ``null=True``, that means it has two possible values |
| 52 | | for "no data": ``NULL``, and the empty string. In most cases, it's redundant to |
| 53 | | have two possible values for "no data;" Django convention is to use the empty |
| 54 | | string, not ``NULL``. |
| 55 | 54 | |
| 56 | 55 | .. note:: |
| 57 | 56 | |
| … |
… |
accepted by :class:`ForeignKey`, plus one extra argument:
|
| 1428 | 1427 | subclassing. |
| 1429 | 1428 | |
| 1430 | 1429 | See :doc:`One-to-one relationships </topics/db/examples/one_to_one>` for usage |
| 1431 | | examples of ``OneToOneField``. |
| | 1430 | examples of ``OneToOneField``. |
| | 1431 | No newline at end of file |