DatabaseError: (1071, 'Specified key was too lo...

python manage.py syncdb出现:

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

原因:

InnoDB has a maximum index length of 767 bytes, so for utf8 or utf8mb4 columns, you can index a maximum of 255 or 191 characters, respectively. If you currently have utf8 columns with indexes longer than 191 characters, you will need to index a smaller number of characters. In an InnoDB table, these column and index definitions are legal:

col1 VARCHAR(500) CHARACTER SET utf8, INDEX (col1(255))

To use utf8mb4 instead, the index must be smaller:

col1 VARCHAR(500) CHARACTER SET utf8mb4, INDEX (col1(191))"

代码里的varchar字段设了255,索引也设了255。

解决方法:
把数据库字符编码utf8mb4改为utf8

你可能感兴趣的:(DatabaseError: (1071, 'Specified key was too lo...)