I have a field in the model,
name = models.CharField(max_length=2000)
and the data entered is,
name='abc'
the django model's max_length
is set to 2000 while the entered data is only of length 3,
Does the max_length
reserves space for 2000 characters in the database table per object? after the model object is saved, does the space is freed up?
Do setting up higher max_length
increase the size of database if the number of objects on database is several thousands or millions?
Database is postgres
The CharField
will be represented by a character varying(max_length)
in PostgreSQL.
From the docs:
The storage requirement for a short string (up to 126 bytes) is 1 byte plus the actual string, which includes the space padding in the case of character. Longer strings have 4 bytes of overhead instead of 1.
So, the disk space the string will take up is dependent on it's length + a small overhead, not on the max length of the field.
Using a higher max_length
will not increase the disk space used by the db.
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