django python 排序错误

发布于 2024-11-30 04:19:26 字数 619 浏览 6 评论 0原文

出现以下错误的原因是什么?当我尝试使用以下内容进行过滤时:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

被你宠の有点坏 2024-12-07 04:19:26

像这样更改 MySQL 中的数据库:

ALTER TABLE foo CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;

创建新数据库时,请记住使用正确的整理设置进行创建:

CREATE DATABASE foo CHARACTER SET utf8 COLLATE utf8_general_ci;

更多讨论 此处

Alter the database in MySQL like so:

ALTER TABLE foo CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;

When creating a new database, remember to create with the right collate settings:

CREATE DATABASE foo CHARACTER SET utf8 COLLATE utf8_general_ci;

More discussion here.

悲欢浪云 2024-12-07 04:19:26

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文