← Back to team overview

harvest-dev team mailing list archive

[Bug 613439] [NEW] review use of Field.null and Field.blank in models

 

Public bug reported:

This is what the Django documentation says and what we're not doing yet:

"""
Field.null
If True, Django will store empty values as NULL in the database. Default is False.

Note that empty string values will always get stored as empty strings,
not as NULL. Only use null=True for non-string fields such as integers,
booleans and dates. For both types of fields, you will also need to set
blank=True if you wish to permit empty values in forms, as the null
parameter only affects database storage (see blank).

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.


Field.blank
If True, the field is allowed to be blank. Default is False.

Note that this is different than null. null is purely database-related, whereas blank is validation-related. If a field has blank=True, validation on Django’s admin site will allow entry of an empty value. If a field has blank=False, the field will be required.
"""

** Affects: harvest
     Importance: Medium
         Status: Triaged


** Tags: data

** Changed in: harvest
   Importance: Undecided => Medium

** Changed in: harvest
       Status: New => Triaged

** Tags added: data

-- 
review use of Field.null and Field.blank in models
https://bugs.launchpad.net/bugs/613439
You received this bug notification because you are a member of harvest-
dev, which is the registrant for harvest.

Status in Harvest Service: Triaged

Bug description:
This is what the Django documentation says and what we're not doing yet:

"""
Field.null
If True, Django will store empty values as NULL in the database. Default is False.

Note that empty string values will always get stored as empty strings, not as NULL. Only use null=True for non-string fields such as integers, booleans and dates. For both types of fields, you will also need to set blank=True if you wish to permit empty values in forms, as the null parameter only affects database storage (see blank).

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.



Field.blank
If True, the field is allowed to be blank. Default is False.

Note that this is different than null. null is purely database-related, whereas blank is validation-related. If a field has blank=True, validation on Django’s admin site will allow entry of an empty value. If a field has blank=False, the field will be required.
"""





Follow ups

References