Ticket #22145: 22145.patch

File 22145.patch, 2.2 KB (added by out0fbound, 11 years ago)

Clarify documentation on Field.blank and Field.null options

  • docs/ref/models/fields.txt

    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.  
    3939If ``True``, Django will store empty values as ``NULL`` in the database. Default
    4040is ``False``.
    4141
    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
     42Avoid using :attr:`~Field.null` on string-based fields such as
     43:class:`CharField` and :class:`TextField` because empty string values will always get
     44stored as empty strings, not as ``NULL``. If a string-based field has ``null=True``,
     45that means it has two possible values for "no data": ``NULL``, and the empty
     46string. In most cases, it's redundant to have two possible values for "no data;"
     47Django convention is to use the empty string, not ``NULL``.
     48
     49Note for both string-based and non-string-based fields, you will also need to set
    4550``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
    4853
    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``.
    5554
    5655.. note::
    5756
    accepted by :class:`ForeignKey`, plus one extra argument:  
    14281427    subclassing.
    14291428
    14301429See :doc:`One-to-one relationships </topics/db/examples/one_to_one>` for usage
    1431 examples of ``OneToOneField``.
     1430examples of ``OneToOneField``.
     1431 No newline at end of file
Back to Top