fb_pixel

How do the Django models specify the binary flag for the varchar field?

Development | Programming languages
Description
Actually, the task is to make such a field in a DBMS that the index on it is built on the principle of a text field(i.e., "a"in sorting before "aa"), but inside it could store and binary data data(ie, distinguished between comparisons of the register and all that).If you do directly in MySQL, then to obtain the required information for the varchar field, specify the binary flag.And how to achieve the same through models.py in Django?

Binary field Django models will make, it seems, is not quite that.
Attachments
No attachments
Info
Description
As an option, you can create a class inherited from the type models.Field
and override the method in it:

def db_type(self, connection):
        return'VARBINARY(% s)'% self.max_length

Then in the model you define a field of this class.

on April 30th, 2020 (10:53 pm)
All coments
This job has not been commented yet.