django python 排序错误
出现以下错误的原因是什么?当我尝试使用以下内容进行过滤时:
if MyObject.objects.filter(location = aDictionary['address']):
其中 location 定义为:
location = models.CharField(max_length=100, blank=True, default='')
当 aDictionary['address'] 包含带有非字母数字字符的字符串(例如 Kīhei)时,我收到以下错误:
File "/usr/lib/pymodules/python2.6/MySQLdb/connections.py", line 35, in defaul
terrorhandler
raise errorclass, errorvalue
_mysql_exceptions.OperationalError: (1267, "Illegal mix of collations (latin1_sw
edish_ci,IMPLICIT) and (utf8_general_ci,COERCIBLE) for operation '='")
What is the reason for the following error? when i try to filter with:
if MyObject.objects.filter(location = aDictionary['address']):
where location is defined as:
location = models.CharField(max_length=100, blank=True, default='')
I get the following error when aDictionary['address'] contains a string with a non-alphanumeric character (for example Kīhei):
File "/usr/lib/pymodules/python2.6/MySQLdb/connections.py", line 35, in defaul
terrorhandler
raise errorclass, errorvalue
_mysql_exceptions.OperationalError: (1267, "Illegal mix of collations (latin1_sw
edish_ci,IMPLICIT) and (utf8_general_ci,COERCIBLE) for operation '='")
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
像这样更改 MySQL 中的数据库:
创建新数据库时,请记住使用正确的整理设置进行创建:
更多讨论 此处。
Alter the database in MySQL like so:
When creating a new database, remember to create with the right collate settings:
More discussion here.
Python 使用 Unicode 字符串,而您的数据库则不然。将数据库排序规则更改为使用 utf8 应该没问题。
Python is using Unicode strings, and your database is not. Change your database collation to use utf8 and you should be fine.