CharField uses the
VARCHAR data type, which uses variable
storage space depending on string length. This normally saves storage space,
but for columns with a fixed length, it adds a small overhead.
CHAR data type avoids that overhead, but it has the
surprising behaviour of removing trailing space characters, and consequently
ignoring them in comparisons.
FixedCharField provides a Django field for
CHAR. This can help you interface with databases created by other
systems, but it’s not recommended for general use, due to the trialing space
- class django_mysql.models.FixedCharField(*args, max_length: int, **kwargs)#
A subclass of Django’s
Charfieldthat uses the
max_lengthis as with
CharField, but must be within the range 0-255.
from django_mysql.models import FixedCharField class Address(Model): zip_code = FixedCharField(length=5)