django-environ
django-environ copied to clipboard
Collation and charset?
Is there a way to define the DB url in such a way that also the COLLATION and CHARSET would get set as below?
'mysql': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'django2',
'USER': 'user',
'PASSWORD': 'password',
'HOST': 'localhost',
'PORT': '3306',
'OPTIONS': {'init_command': 'SET storage_engine=INNODB'},
'STORAGE_ENGINE': 'INNODB',
'COLLATION': 'utf8-general_ci',
'CHARSET': 'utf-8',
},
thanks a lot!
Same question here (for an external project). Looking at the source of db_url_config
, it's not yet possible but it can be fixed. The STORAGE_ENGINE
, COLLATION
and CHARSET
should be added to _DB_BASE_OPTIONS
we we can write:
mysql://user:pass@localhost/django2?COLLATION=utf8-general_ci&CHARSET=utf-8
Adding &STORAGE_ENGINE=INNODB&init_comment=SET storage_engine=INNODB
are likely not needed, since these are defaults since MySQL 5.5.5 and that's the minimal version Django supports.
Got 'TypeError: keywords must be strings.' when doing this.
Update: The correct way is using lower case: '?charset=utf8'