Error: #1071 - Specified key was too long; max key length is 1000 bytes - mysql 5.0.91

后端 未结 4 1010
攒了一身酷
攒了一身酷 2021-01-25 09:39

I am using mysql 5.0.91 and I need to save URLs ( some are small and some are very long ). I want to use varchar(2000) but I get an error:

#1

4条回答
  •  甜味超标
    2021-01-25 10:12

    Do you use unique=True on your urls column? MySQL is building a unique index on that column, and the number of bytes that it uses per character varies depending on the encoding.

    If it is UTF-16, for example, it will use 2 bytes per character, so your varchar(2000) column would be 4000 bytes, and as the error message says, the max key length is 1000 bytes.

    So you can switch to UTF-8 and use varchar(900) instead to fix this problem.

提交回复
热议问题