Project

Profile

Help

Issue #3446

Updated by dalley about 6 years ago

Using null=True with CharField and TextField is recommended against and is also essentially a no-op. 

 https://docs.djangoproject.com/en/2.0/ref/models/fields/#null 


 > 

 <pre> 
 If True, Django will store empty values as NULL in the database. Default is False. 
 >  
 > 

 Avoid using null on string-based fields such as CharField and 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. One exception is when a 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 null parameter only affects database storage (see blank). 
 >  

 </pre> 

 https://docs.djangoproject.com/en/2.0/ref/models/fields/#blank 


 > 

 <pre> 
 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, form validation will allow entry of an empty value. If a field has blank=False, the field will be required. 
 > </pre>

Back