Resizable Text/Binary Fields¶
Django’s TextField
and
BinaryField
fields are fixed at the MySQL level to
use the maximum size class for the BLOB
and TEXT
data types. This is
fine for most applications, however if you are working with a legacy database,
or you want to be stricter about the maximum size of data that can be stored,
you might want one of the other sizes.
The following field classes are simple subclasses that allow you to provide an extra parameter to determine which size class to use. They work with migrations, allowing you to swap them for the existing Django class and then use a migration to change their size class. This might help when taking over a legacy database for example.
- class django_mysql.models.SizedTextField(size_class: int, **kwargs)¶
A subclass of Django’s
TextField
that allows you to use the other sizes ofTEXT
data type. Setsize_class
to:1
for aTINYTEXT
field, which has a maximum length of 255 bytes2
for aTEXT
field, which has a maximum length of 65,535 bytes3
for aMEDIUMTEXT
field, which has a maximum length of 16,777,215 bytes (16MiB)4
for aLONGTEXT
field, which has a maximum length of 4,294,967,295 bytes (4GiB)
- class django_mysql.models.SizedBinaryField(size_class, **kwargs)¶
A subclass of Django’s
BinaryField
that allows you to use the other sizes ofBLOB
data type. Setsize_class
to:1
for aTINYBLOB
field, which has a maximum length of 255 bytes2
for aBLOB
field, which has a maximum length of 65,535 bytes3
for aMEDIUMBLOB
field, which has a maximum length of 16,777,215 bytes (16MiB)4
for aLONGBLOB
field, which has a maximum length of 4,294,967,295 bytes (4GiB)