ogzd
ogzd

Reputation: 5692

DatabaseError: (1071, 'Specified key was too long; max key length is 767 bytes')

I have a django project and I would like to run some unit tests. When I try: python manage.py test it throws this error and I couldn't find much information about it in here.

my db settings in settings.py:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'mydb',
        'USER': 'root',
        'PASSWORD': 'password',
        'HOST': 'localhost',           
        'PORT': '3306', 
    }
} 

It looks like something related with InnoDB and MyISAM but I have no idea what is wrong and how to fix it. Thanks!

django version: 1.5.4
mysql version: 5.5

Also, there is no unique=True set in any of the django models.

Upvotes: 5

Views: 7012

Answers (4)

saifulislamrokon
saifulislamrokon

Reputation: 21

I have fixed the subject issue creating a new database like below:

DROP DATABASE IF EXISTS databasename;

CREATE DATABASE databasename DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci;

Upvotes: 1

Giuseppe De Marco
Giuseppe De Marco

Reputation: 701

solution is

ALTER DATABASE `databasename` CHARACTER SET utf8; 

as already exposed here

https://stackoverflow.com/a/43365860/7708836

Upvotes: 11

Nids Barthwal
Nids Barthwal

Reputation: 2419

Create your database using the following command CREATE DATABASE CHARACTER SET utf8;

Upvotes: 0

ogzd
ogzd

Reputation: 5692

I found my own solution.

If you have somehow this in your my.cnf:

 character-set-server = utf8mb4
 collation-server = utf8mb4_unicode_ci

Then it creates this 'too much bytes' problem. Reverted it back to good old utf8 and it helped.

Upvotes: 2

Related Questions