[Django]-Django database charset issue

6👍

Answer: Django uses ‘utf-8’ as the default charset for the database, so if your database uses any other charset (mostly legacy database would be configured with ‘latin1’) then the charset need to be explicitly mentioned under database settings. Settings Ex:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'test_db',
        'USER': 'root',
        'PASSWORD': '',
        'HOST': '',
        'PORT': '3306',
        'OPTIONS': {
                    'charset': 'latin1',
                    'use_unicode': True, },
    }, 
}

In addition to this, if you don’t need to use unicode then you can set the ‘use_unicode’ to False but i guess that is not recommended.

Cheers !!!

Leave a comment