When I was doing the development with a recent project, I found out this err:


ERROR 1071 (42000) at line 50: Specified key was too long; max key length is 767 bytes

See here is one of my model class with url as an unique string.

Needone mysql error python

As UTF8 is three bytes per character by default to store a string, and key in mysql is just 767 bytes long in total. If the string is too long which cannot be used as a key as it will exceed the size. in this case, 1000 * 3 = 3000 (bytes) > 767.

The solution can be:

  1. Remove the unique = True