Set the column collate directly from the django model field CharField

Viewed 38

My tables default collate are utf8mb4_general_ci but sometimes I need only few columns to be utf8_general_ci.

Is there a library or a workaround to set the db columns collate directly from the model fields like this:

name = models.CharField(max_length=255, db_index=True, collate='utf8_general_ci')
1 Answers

There is no need for a workaround, setting the collation for a CharField is supported since Django 3.2 by using the db_collation argument:

name = models.CharField(max_length=255, db_index=True, db_collation='utf8_general_ci')
Related