Universal field options

Table A.2 lists all the optional field arguments in Django. They are available to all field types.

Option

Description

null

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 because empty string values will always be stored as empty strings, not as 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. If you want to accept null values with BooleanField, use NullBooleanField instead.

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 ...

Get Mastering Django: Core now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.