错误发生背景
这周django执行 python manage.py migrate 迁移生成表时候报 Specified key was too long; max key length is 767 bytes 经过简单的分析是字符串长度大于767bytes,后来网上查询处理后面报 :index column size too large. the maximum column size is 767 bytes
解决处理
经网上的说法修改innodb_file_format 和 innodb_large_prefix 两个值,结果还是报 index column size too large. the maximum column size is 767 bytes
set global innodb_file_format = BARRACUDA
set global innodb_large_prefix = ON
# 查看是否生效
show variables like 'character%';
show variables like 'collation_%';
show variables like 'innodb_large_prefix';
show variables like 'innodb_file_format';
后来我想了想本地的是好的,然后我看了下两者的区别,发现本地mysql版本是5.7,字符集utf8mb4;测试环境是mysql版本是5.6 字符集原来是utf8,后来我改成了utf8mb4,后面尝试将测试环境的字符集改成utf8在执行迁移就成功了。
学习连接
那些从MySQL5.6升级到5.7的坑--innodb_large_prefix
mysql中的utf8mb4、utf8mb4_unicode_ci、utf8mb4_general_ci
人总有一天会长大,何必成熟太早,失去太早。