Skip to main content

Model Field Types

All model fields inherit from the base Field class and accept common parameters.

Base Field Class

Field

Base class for all field types.
verbose_name
str
Human-readable name for the field. If not provided, Django will automatically create it from the field name.
name
str
The name of the field. In most cases, this is automatically set by Django.
primary_key
bool
default:"False"
If True, this field is the primary key for the model.
max_length
int
Maximum length for string-based fields. Required for CharField and its subclasses.
unique
bool
default:"False"
If True, this field must be unique throughout the table.
blank
bool
default:"False"
If True, the field is allowed to be blank in forms. Note this is different from null.
null
bool
default:"False"
If True, Django will store empty values as NULL in the database.
db_index
bool
default:"False"
If True, a database index will be created for this field.
default
The default value for the field. Can be a value or a callable object.
db_default
A database-computed default value (expression or literal). Requires database support.
editable
bool
default:"True"
If False, the field will not be displayed in the admin or any other ModelForm.
serialize
bool
default:"True"
If False, the field will not be serialized when the model is passed to Django’s serializers.
unique_for_date
str
Set this to the name of a DateField or DateTimeField to require that this field be unique for the value of the date field.
unique_for_month
str
Like unique_for_date, but requires the field to be unique with respect to the month.
unique_for_year
str
Like unique_for_date and unique_for_month, but for the year.
choices
Iterable
An iterable of 2-tuples to use as choices for this field. If provided, the default form widget will be a select box.
help_text
str
default:"''"
Extra “help” text to be displayed with the form widget.
db_column
str
The name of the database column to use for this field. If not provided, Django will use the field’s name.
db_comment
str
A comment on the database column. Requires database support for comments.
db_tablespace
str
The name of the database tablespace to use for this field’s index, if applicable.
validators
list
default:"[]"
A list of validators to run for this field.
error_messages
dict
A dictionary of error messages to override the default messages that the field will raise.

String Fields

CharField

A string field for small- to large-sized strings.
max_length
int
required
The maximum length (in characters) of the field. Required.
db_collation
str
The database collation name for the field.
Reference: django/db/models/fields/__init__.py:1204

TextField

A large text field.
db_collation
str
The database collation name for the field.
Reference: django/db/models/fields/__init__.py:2482

EmailField

A CharField that checks that the value is a valid email address.
max_length
int
default:"254"
Maximum length defaults to 254 to comply with RFCs 3696 and 5321.
Reference: django/db/models/fields/__init__.py:1955

SlugField

A field for storing URL slugs (short labels containing only letters, numbers, underscores or hyphens).
max_length
int
default:"50"
Maximum length of the slug.
db_index
bool
default:"True"
Creates a database index by default.
allow_unicode
bool
default:"False"
If True, the field accepts Unicode letters in addition to ASCII letters.
Reference: django/db/models/fields/__init__.py:2445

URLField

A CharField for a URL, validated by URLValidator.
max_length
int
default:"200"
Maximum length defaults to 200.
Reference: django/db/models/fields/__init__.py:2677

Numeric Fields

IntegerField

An integer field. Values from -2147483648 to 2147483647 are safe in all databases supported by Django. Reference: django/db/models/fields/__init__.py:2099

BigIntegerField

A 64-bit integer. Values from -9223372036854775808 to 9223372036854775807 are safe. Reference: django/db/models/fields/__init__.py:2199

SmallIntegerField

Like IntegerField, but only allows values under a certain (database-dependent) point. Reference: django/db/models/fields/__init__.py:2216

PositiveIntegerField

Like IntegerField, but must be either positive or zero (0). Values from 0 to 2147483647 are safe. Reference: django/db/models/fields/__init__.py:2415

PositiveBigIntegerField

Like PositiveIntegerField, but allows values from 0 to 9223372036854775807. Reference: django/db/models/fields/__init__.py:2400

PositiveSmallIntegerField

Like PositiveIntegerField, but only allows values under a certain (database-dependent) point. Reference: django/db/models/fields/__init__.py:2430

FloatField

A floating-point number represented in Python by a float instance. Reference: django/db/models/fields/__init__.py:2057

DecimalField

A fixed-precision decimal number, represented in Python by a Decimal instance.
max_digits
int
required
The maximum number of digits allowed in the number.
decimal_places
int
required
The number of decimal places to store with the number.
Reference: django/db/models/fields/__init__.py:1698

Boolean Fields

BooleanField

A true/false field. The default form widget is CheckboxInput, or NullBooleanSelect if null=True. Reference: django/db/models/fields/__init__.py:1158

Date and Time Fields

DateField

A date, represented in Python by a datetime.date instance.
auto_now
bool
default:"False"
Automatically set the field to now every time the object is saved.
auto_now_add
bool
default:"False"
Automatically set the field to now when the object is first created.
Reference: django/db/models/fields/__init__.py:1422

DateTimeField

A date and time, represented in Python by a datetime.datetime instance.
auto_now
bool
default:"False"
Automatically set the field to now every time the object is saved.
auto_now_add
bool
default:"False"
Automatically set the field to now when the object is first created.
Reference: django/db/models/fields/__init__.py:1557

TimeField

A time, represented in Python by a datetime.time instance.
auto_now
bool
default:"False"
Automatically set the field to now every time the object is saved.
auto_now_add
bool
default:"False"
Automatically set the field to now when the object is first created.
Reference: django/db/models/fields/__init__.py:2559

DurationField

A field for storing periods of time, represented in Python by timedelta. Reference: django/db/models/fields/__init__.py:1894

Binary and Other Fields

BinaryField

A field to store raw binary data.
editable
bool
default:"False"
Binary fields are not editable by default.
Reference: django/db/models/fields/__init__.py:2702

UUIDField

A field for storing universally unique identifiers. Uses Python’s UUID class. Reference: django/db/models/fields/__init__.py:2766

FilePathField

A CharField whose choices are limited to the filenames in a certain directory on the filesystem.
path
str
required
The absolute filesystem path to a directory from which this FilePathField should get its choices.
match
str
A regular expression as a string that FilePathField will use to filter filenames.
recursive
bool
default:"False"
If True, includes subdirectories of path.
allow_files
bool
default:"True"
If True, includes files in the specified location.
allow_folders
bool
default:"False"
If True, includes folders in the specified location.
max_length
int
default:"100"
Maximum length of the path.
Reference: django/db/models/fields/__init__.py:1981

GenericIPAddressField

An IPv4 or IPv6 address, in string format (e.g. 192.0.2.30 or 2a02:42fe::4).
protocol
str
default:"'both'"
Limits valid inputs to the specified protocol. Accepted values are ‘both’, ‘IPv4’, or ‘IPv6’.
unpack_ipv4
bool
default:"False"
If True, unpacks IPv4-mapped IPv6 addresses like ::ffff:192.0.2.1.
Reference: django/db/models/fields/__init__.py:2254

Auto Fields

AutoField

An IntegerField that automatically increments.
primary_key
bool
default:"True"
Auto fields must be primary keys.
Reference: django/db/models/fields/__init__.py:2910

BigAutoField

A 64-bit integer that automatically increments. Reference: django/db/models/fields/__init__.py:2918

SmallAutoField

Like AutoField, but only allows values under a certain (database-dependent) limit. Reference: django/db/models/fields/__init__.py:2926

Build docs developers (and LLMs) love