Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

django test database is not created with utf8

I am using utf-8 general case insensitive for for mysql database, but django creates a test db with latin collation

I have set this:

TEST_CHARSET="utf8_general_ci"

TEST_COLLATION="utf8_general_ci"

In the settings file, but to no avail.

What else should i do?

like image 317
vasion Avatar asked Oct 15 '12 11:10

vasion


4 Answers

TEST_CHARSET and TEST_COLLATION are renamed to CHARSET and COLLATION and moved to TEST dictionary in Django 1.8:

DATABASES = {
    ...
    'TEST': {
        'CHARSET': 'utf8',
        'COLLATION': 'utf8_general_ci',
    }
}
like image 179
dexity Avatar answered Nov 08 '22 19:11

dexity


in settings add:

DATABASES = {
    'default': {
        ...
        'TEST_CHARSET': "utf8",
        'TEST_COLLATION': "utf8_general_ci",
    }
}
like image 30
maciejga Avatar answered Nov 08 '22 20:11

maciejga


Please see here: https://docs.djangoproject.com/en/1.11/ref/settings/#std:setting-DATABASE-TEST

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': <db_name>,
        'USER': <user>,
        'PASSWORD': <password>,
        'HOST': <host>,
        'PORT': <port>,
        'TEST': {
            'NAME': <test_db_name>,
            'CHARSET': 'utf8',
            'COLLATION': 'utf8_general_ci',
        },
    },
}
like image 9
Stanislav Avatar answered Nov 08 '22 18:11

Stanislav


I had the same problem and spent hours of figuring it out until noticed that

TEST_CHARSET
TEST_COLLATION

should be a part of the DATABASES, not settings.py. It's very easy to mix them up...

https://docs.djangoproject.com/en/dev/ref/settings/#testing

like image 1
Maxim Avatar answered Nov 08 '22 20:11

Maxim