Search code examples
mysqldjangodjango-databasedjango-mysql

How to use default-character-set in django - mysql database connection


So, I was re-configuring my SQL and decided to move back from my.conf to settings.py (context: https://docs.djangoproject.com/en/3.2/ref/databases/#mysql-notes)

'read_default_file': '/path/to/my.cnf',

# my.cnf
[client]
database = NAME
user = USER
password = PASSWORD
default-character-set = utf8

So I was shifting from my.conf to settings.py I got an error

TypeError: 'default-character-set' is an invalid keyword argument for connect

My code:

'Options':{
      'default-character-set': utf8
      }

Solution

  • The option is charset

    'Options':{
        'charset': 'utf8mb4'
    }