问题
I need to set default Collation for MySQL tables with Django 2.*, im using mysqlclient, my settings are:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': '',
'USER': '',
'PASSWORD': '',
'HOST': 'localhost',
'PORT': '3306',
'OPTIONS': {
'charset': 'utf8mb4',
},
}
}
'charset': 'utf8mb4',
This parameter seems don't work properly and tables in DB utf8. Although i want to manually set and tables Collation to utf8mb4_general_ci
Will be appreciate for any clues.
回答1:
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': '',
'USER': '',
'PASSWORD': '',
'HOST': 'localhost',
'PORT': '3306',
'OPTIONS': {
'init_command': 'ALTER DATABASE <YOUR_DB_NAME> CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci',
},
}
Thanks to https://stackoverflow.com/a/6115705/2891421
来源:https://stackoverflow.com/questions/49316327/how-to-set-collation-in-mysql-database-with-django-2-mysqlclient