17

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?

RedBencity
  • 709
  • 5
  • 5
vasion
  • 1,237
  • 3
  • 18
  • 29

6 Answers6

29

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',
    }
}
dexity
  • 756
  • 7
  • 7
12

in settings add:

DATABASES = {
    'default': {
        ...
        'TEST_CHARSET': "utf8",
        'TEST_COLLATION': "utf8_general_ci",
    }
}
maciejga
  • 121
  • 1
  • 3
9

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',
        },
    },
}
Stanislav
  • 826
  • 11
  • 17
1

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

Maxim
  • 52,561
  • 27
  • 155
  • 209
0

As others have pointed out, you need something like this to create the database

DATABASES = {
    ...
    'TEST': {
        'CHARSET': 'utf8mb4',
        'COLLATION': 'utf8mb4_unicode_ci',
    }
}

But you also will want to make sure that you have something like this as well, to make sure that your tests communicate with the db with the appropriate charset.

DATABASES = {
    ...
    'OPTIONS': {
        'charset': 'utf8mb4'
     }
}
Nate
  • 321
  • 3
  • 6
-2

Take a look at the settings file example here: https://docs.djangoproject.com/en/dev/ref/databases/#connecting-to-the-database

sampson-chen
  • 45,805
  • 12
  • 84
  • 81