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

sql error 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
error code 1071 specified key was too long; max key length is 767 bytes mysql
warning 1071 specified key was too long; max key length is 767 bytes
kernel error error 1071 42000 specified key was too long max key length is 767 bytes
error 1071 42000 at line 165 specified key was too long; max key length is 767 bytes
db exec failed error 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.

solution is

ALTER DATABASE `databasename` CHARACTER SET utf8; 

as already exposed here

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

python, solution is. ALTER DATABASE `databasename` CHARACTER SET utf8;. as already exposed here. https://stackoverflow.com/a/43365860/7708836. Stack Overflow Public questions and answers; Teams Private questions and answers for your team; Enterprise Private self-hosted questions and answers for your enterprise; Talent Hire technical talent

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.

MySql: DatabaseError: (1071, 'Specified key was too long; max key , python manage.py syncdb MySql: DatabaseError: (1071, 'Specified key was too long; max key length is 1000 bytes') Stack Overflow for Teams is a private, secure spot for you and your coworkers to find and share information. Learn more DatabaseError: (1071, 'Specified key was too long; max key length is 767 bytes')

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

Mysql error 1071 : Specified key was too long; max key length is 767 , characters will trigger a mysql error 1071 when migrating djcelery django.db.​utils.DatabaseError: (1071, 'Specified key was too long; max DatabaseError: (1071, 'Specified key was too long; max key length is 767 bytes')

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;

T3322 "1071: Specified key was too long" (MySQL error) during , A database error has occurred. Query: CREATE TABLE mw_categorylinks ( cl_from int(8) unsigned NOT NULL default '0', cl_to varchar(255) binary NOT NULL  @snake29 I was looking every where for a solution untill I found this post. This worked very well. No problems and was able to excute occ command again.

T193222 Error: 1071 Specified key was too long; max key length is , sql comes with two varchar(255) combined into a PRIMARY KEY. That caused the testsuite to fail creating that imagelinks table with: Error: 1071 Specified key was  For the Love of Physics - Walter Lewin - May 16, 2011 - Duration: 1:01:26. Lectures by Walter Lewin. They will make you ♥ Physics. Recommended for you

[fix] Database error 1071 'Specified Key , [fix] Database error 1071 'Specified Key was too long'. Post by samtherobot » 10:​05pm, Tue 08 Jan, 2008. For me this problem occurred because phplist cannot  Qualify the column with the appropriate table name: mysql> SELECT t2.i FROM t INNER JOIN t AS t2; Modify the query to avoid the need for qualification:

#21308 (DatabaseError running tests with MySQL & utf8mb4 charset , python mysite/manage.py test Creating test database for alias 'default' DatabaseError: (1071, 'Specified key was too long; max key length is 767 bytes'). Stack Overflow for Teams is a private, secure spot for you and your coworkers to find and share information. Learn more #1071 - Specified key was too long; max key length is 1000 bytes

Comments
  • Possible duplicate of stackoverflow.com/questions/8746207/…
  • Oh goodness! Somebody is running with a silly key declaration.
  • @That1Guy same error, different approachs. I am not creating any ddl on my own
  • Fair enough. I didn't flag.
  • Possible duplicate of #1071 - Specified key was too long; max key length is 767 bytes
  • Did not work for me with Mariadb 10 GA, any other solution on your experience? Tried almost everything wihtout results...
  • it has been a long time that I tackled with this problem, right now I don't remember anything :-) so goodluck to you.
  • I finally could solve it by altering varchar length from index columns to lower than 256 values
  • You can do it per database with CREATE DATABASE <dbname> CHARACTER SET utf8; (from the django manual). Tested successfully with MariaDB 10.0.27.