mirror of
				https://github.com/django/django.git
				synced 2025-10-31 01:25:32 +00:00 
			
		
		
		
	Fixed #22145 -- Clarified docs on Field.blank and Field.null options.
Thanks skipjack at peru.com for the suggestion.
This commit is contained in:
		
				
					committed by
					
						 Tim Graham
						Tim Graham
					
				
			
			
				
	
			
			
			
						parent
						
							4132e013ec
						
					
				
				
					commit
					3390550f6f
				
			| @@ -39,19 +39,17 @@ The following arguments are available to all field types. All are optional. | |||||||
| If ``True``, Django will store empty values as ``NULL`` in the database. Default | If ``True``, Django will store empty values as ``NULL`` in the database. Default | ||||||
| is ``False``. | 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 |  | ||||||
| :attr:`~Field.null` parameter only affects database storage (see |  | ||||||
| :attr:`~Field.blank`). |  | ||||||
|  |  | ||||||
| Avoid using :attr:`~Field.null` on string-based fields such as | Avoid using :attr:`~Field.null` on string-based fields such as | ||||||
| :class:`CharField` and :class:`TextField` unless you have an excellent reason. | :class:`CharField` and :class:`TextField` because empty string values will | ||||||
| If a string-based field has ``null=True``, that means it has two possible values | always be stored as empty strings, not as ``NULL``. If a string-based field has | ||||||
| for "no data": ``NULL``, and the empty string. In most cases, it's redundant to | ``null=True``, that means it has two possible values for "no data": ``NULL``, | ||||||
| have two possible values for "no data;" Django convention is to use the empty | and the empty string. In most cases, it's redundant to have two possible values | ||||||
| string, not ``NULL``. | for "no data;" the Django convention is to use the empty string, not ``NULL``. | ||||||
|  |  | ||||||
|  | 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 | ||||||
|  | :attr:`~Field.null` parameter only affects database storage | ||||||
|  | (see :attr:`~Field.blank`). | ||||||
|  |  | ||||||
| .. note:: | .. note:: | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user