1271, Illegal mix of collations for operation 'like'(django)

1271, Illegal mix of collations for operation 'like'(django)

问题

MySQL Illegal mix of collations for operation 'like', MySQL 5.5 以上, 若字段类型 Type 是 time,date,datetime

在 select时如果使用 like '%中文%' 会出现 Illegal mix of collations for operation 'like'。执行时可能就会出现时间字段 like '%中文%' 这种语法,,旧版的 MySQL 是不会出现错误的。升到 MySQL 5.5 以上, 必需改成 like binary '%中文%' 即可避免出现错误

解决

C:pythonpyLibsite-packagesdjangodbackendsmysqlase.py

'icontains': 'LIKE %s', 改为: 'icontains': 'LIKE BINARY %s',

重启之后 模糊查询就可以了

原文地址:https://www.cnblogs.com/jhpy/p/14202172.html