django.db.utils.OperationalError: (1071, 'Specified key was too long; max key length is 767 bytes') django.db.utils.OperationalError: (1071, 'Specified key was too long; max key length is 767 bytes') database database

django.db.utils.OperationalError: (1071, 'Specified key was too long; max key length is 767 bytes')


solution is

ALTER DATABASE `databasename` CHARACTER SET utf8; 


You can recreate "database" again:

CREATE DATABASE mydatabase CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci;

or change config file. Open /etc/mysql/mariadb.conf.d/50-server.cnf and change:

character-set-server  = utf8collation-server      = utf8_general_ci


The previous two answers did not help in my case, so I'm posting my solution to my case when your limit is 1000 (i.e. 1071, 'Specified key was too long; max key length is 1000 bytes').

First of all, make sure you are working on utf8 encoding!

Then, navigate to your setting file my.ini, find the line default-storage-engine=xxx. If it is

default-storage-engine=MYISAM

please change to

default-storage-engine=InnoDB

Then, the problem should be solved.

The reason is simply because MYISAM does not support key size greater than 1000 bytes.