There is no difference between PositiveInteger and PositiveSmallInteger field in the Django source code. But, Django documentation says,
PositiveInteger starts from 0 to 2147483647 and PositiveSmallInteger starts from 0 to 32767.
Please clarify me what is the difference between these two types.
Thanks in advance.
Fields in Django are the data types to store a particular type of data. For example, to store an integer, IntegerField would be used. These fields have in-built validation for a particular data type, that is you can not store “abc” in an IntegerField. Similarly, for other fields.
PositiveIntegerField is a integer number represented in Python by a int instance. This field is like a IntegerField but must be either positive or zero (0). The default form widget for this field is a NumberInput when localize is False or TextInput otherwise.
In Emptoris® Sourcing, integer fields are fields in which you can make number entries and if required also use the values for calculations. Other than the basic information required for creating this field type, the table following table lists some additional fields.
According to documentation, An AutoField is an IntegerField that automatically increments according to available IDs. One usually won't need to use this directly because a primary key field will automatically be added to your model if you don't specify otherwise.
This is one of those things that is the way it is because it got that way.
Django supports SmallIntegerField
because Django grew up on PostgreSQL, and PostgreSQL supports smallint. The PosgreSQL docs say
The smallint type is generally only used if disk space is at a premium.
Also there's a difference in the code if you check the backends of Django. There you see it uses the SMALLINT
feature on some databases, for example sqlite.
...
class FlexibleFieldLookupDict:
# Maps SQL types to Django Field types. Some of the SQL types have multiple
# entries here because SQLite allows for anything and doesn't normalize the
# field type; it uses whatever was given.
base_data_types_reverse = {
'bool': 'BooleanField',
'boolean': 'BooleanField',
'smallint': 'SmallIntegerField',
'smallint unsigned': 'PositiveSmallIntegerField',
'smallinteger': 'SmallIntegerField',
'int': 'IntegerField',
'integer': 'IntegerField',
'bigint': 'BigIntegerField',
'integer unsigned': 'PositiveIntegerField',
'decimal': 'DecimalField',
'real': 'FloatField',
...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With