Model fields

https://www.webforefront.com/django/modeldatatypesandvalidation.html

Data typeDjango model typeSQLiteMySQLPostgreSQLOracleNotes
Binarymodels.BinaryField()BLOB NOT NULLlongblob NOT NULLbytea NOT NULLBLOB NULLCreates a blob field to store binary data (e.g. images,audio or other multimedia objects)
Booleanmodels.BooleanField()bool NOT NULLbool NOT NULLboolean NOT NULLNUMBER(1) NOT NULL CHECK ("VAR" IN(0,1))Creates a boolean field to store True/False (or 0/1)values
Booleanmodels.NullBooleanField()bool NULLbool NULLboolean NULLNUMBER(1) NULL CHECK (("VAR" IN (0,1)) OR ("VAR" IS NULL))Works just like BooleanField but also allows NULL values
Date/timemodels.DateField()date NOT NULLdate NOT NULLdate NOT NULLDATE NOT NULLCreates a date field to store dates
Date/timemodels.TimeField()time NOT NULLtime NOT NULLtime NOT NULLTIMESTAMP NOT NULLCreates a time field to store times.
Date/timemodels.DateTimeField()datetime NOT NULLdatetime NOT NULLtimestamp with time zone NOT NULLTIMESTAMP NOT NULLCreates a datetime field to store dates with times
Date/timemodels.DurationField()bigint NOT NULLbigint NOT NULLinterval NOT NULLINTERVAL DAY(9) TO SECOND(6) NOT NULLCreates a field to store periods of time.
Numbermodels.AutoField()integer NOT NULL AUTOINCREMENTinteger AUTO_INCREMENT NOT NULLserial NOT NULLNUMBER(11) NOT NULL & also creates a SEQUENCE and TRIGGER to increase the fieldCreates an integer that autoincrements, primarly used for custom primary keys
Numbermodels.BigIntegerField()bigint NOT NULLbigint NOT NULLbigint NOT NULLNUMBER(19) NOT NULLCreate a big integer to fit numbers between -9223372036854775808 to 9223372036854775807. This range may vary depending on the DB brand
Numbermodels.DecimalField(decimal_places=X,max_digits=Y)decimal NOT NULLnumeric(X, Y) NOT NULLnumeric(X, Y) NOT NULLNUMBER(10, 3) NOT NULLEnforces a number have a maximum X digits and Y decimal points Creates a decimal field to store decimal numbers. Note both X and Y arguments are required, where the X argument represents the maximum number of digits to store and the Y argument represents the number of decimal places to store.
Numbermodels.FloatField()real NOT NULLdouble precision NOT NULLdouble precision NOT NULLDOUBLE PRECISION NOT NULLCreates a column to store floating-point numbers.
Numbermodels.IntegerField()integer NOT NULLinteger NOT NULLinteger NOT NULLNUMBER(11) NOT NULLCreates a column to store integer numbers.
Numbermodels.PositiveIntegerField()integer unsigned NOT NULLinteger UNSIGNED NOT NULLinteger NOT NULL CHECK ("VAR" >= 0)NUMBER(11) NOT NULL CHECK ("VAR" >= 0)Enforces values from 0 to 2147483647 Works just like IntegerField but limits values to positive numbers
Numbermodels.PositiveSmallIntegerField()smallint unsigned NOT NULLsmallint UNSIGNED NOT NULLsmallint NOT NULL CHECK ("VAR" >= 0)NUMBER(11) NOT NULL CHECK ("VAR" >= 0)Enforces values from 0 to 32767 Works just like IntegerField and the specialized PositiveIntegerField but limits numbers to a smaller positive range.
Numberoptions.SmallIntegerField()smallint NOT NULLsmallint NOT NULLsmallint NOT NULLNUMBER(11) NOT NULLEnforces a number is in the range from -32768 to 32767 Works just like IntegerField but in a smaller integer range.
Textmodels.CharField(max_length=N)varchar(N) NOT NULLvarchar(50) NOT NULLvarchar(50) NOT NULLNVARCHAR2(50) NULLCreates a text column, where the max_length argument is required to specify the maximum length in characters.
Textmodels.TextField()text NOT NULLlongtext NOT NULLtext NOT NULLNCLOB NULLCreates a text field to store text.
Text (Specialized)models.CommaSeparatedIntegerField(max_length=50)varchar(N) NOT NULLvarchar(N) NOT NULLvarchar(N) NOT NULLNVARCHAR2(N) NULLEnforces the string a CSV of integers.Works just like CharField except Django enforces the string be a comma separated value of integers prior to interacting with the database (e.g. 3,54,54,664,65)
Text (Specialized)models.EmailField()varchar(254) NOT NULLvarchar(254) NOT NULLvarchar(254) NOT NULLNVARCHAR2(254) NULLEnforces the text is a valid email with the internal Django EmailValidator to determine what is and isn't a valid. Works just like CharField defaulting to a max_length of 254 characters and also enforces the string is a valid email.
Text (Specialized)models.FileField()varchar(100) NOT NULLvarchar(100) NOT NULLvarchar(100) NOT NULLNVARCHAR2(100) NULLEnforces and provides various utilities to handle files (e.g. opening/closing file, upload location,etc). Works just like CharField defaulting to a max_length of 100 characters and also enforces the string is a valid file.
Text (Specialized)models.FilePathField()varchar(100) NOT NULLvarchar(100) NOT NULLvarchar(100) NOT NULLNVARCHAR2(100) NULLEnforces and provides various utilities to limit choices of filenames in certain filesystem directories. Works just like CharField defaulting to a max_length of 100 characters and also enforces the string is a valid file in a filesystem directory.
Text (Specialized)models.ImageField()varchar(100) NOT NULLvarchar(100) NOT NULLvarchar(100) NOT NULLNVARCHAR2(100) NULLEnforces and provides various utilities to handle image files (e.g. getting the height & width) Works just like CharField and the specialized FileField defaulting to a max_length of 100 characters and also enforces the string is a valid image. Note this field requires the presence of the Pillow Python library (e.g. pip install Pillow).
Text (Specialized)models.GenericIPAddressField()char(39) NOT NULLchar(39) NOT NULLinet NOT NULLVARCHAR2(39) NULLEnforces and provides various utilities to only accept valid IPv4 or IPv6 addresses (e.g. 198.10.22.64 and FE80::0202:B3FF:FE1E:8329, as well as utilities like unpack_ipv4 and protocol) Works just like CharField defaulting to a max_length of 39 characters and enforces the string is a valid IP address.
Text (Specialized)models.SlugField()varchar(50) NOT NULLvarchar(50) NOT NULLvarchar(50) NOT NULLNVARCHAR2(50) NULLEnforces a string is a slug string, which is a string that only contains letters, numbers, underscores or hyphens. Works just like CharField defaulting to a max_length of 50 characters and ensure the provided string is a slug -- a concept that's typically used to cleanse URL strings that contains spaces and other potentially invalid character like letter with accents.
Text (Specialized)models.URLField()varchar(200) NOT NULLvarchar(200) NOT NULLvarchar(200) NOT NULLNVARCHAR2(200) NULLEnforces the provided text value is a valid URL Works just like CharField defaulting to a max_length of 200 characters and enforces the string is a valid URL
Text (Specialized)models.UUIDField()char(32) NOT NULLchar(32) NOT NULLuuid NOT NULLVARCHAR2(32) NOT NULLEnforces the provided text is a Universally unique identifiers (UUID) Works just like CharField defaulting to a max_length of 32 characters and enforces the value is a UUID.