在django中对区分大小写的'精确'查询返回多个不同的结果(Multiple different results returned on case

编程入门 行业动态 更新时间:2024-10-11 13:24:38
在django中对区分大小写的'精确'查询返回多个不同的结果(Multiple different results returned on case-sensitive 'exact' query in django)

我有一个django 1.2.1在一个mysql 5后端运行在Ubuntu的实例。 我试图做一个区分大小写的查询,应该只返回一个结果,但我得到两个具有相同内容但结果不同的结果。

我想获得一个具有以下标题的条目:Cat on the Internet syndrome

所以我使用以下查询:

c = Change.objects.filter(change_type='new',title__exact='Cat on the Internet syndrome')

我得到以下结果:

>>> c [<Change: Change object>, <Change: Change object>]

每个Change对象的标题:

>>> for i in c: ... print i.title ... Cat on the Internet Syndrome Cat on the Internet syndrome

正如你所看到的,每个对象标题中的“S”在综合征中有不同的情况。 我在阅读文档[0]时感觉所有查询都默认为“确切”类型。 当我没有指定title__exact='Cat on the Internet syndrome'时,我得到了相同的结果。

如何确保在上面概述的查询中使用区分大小写?

[0] http://docs.djangoproject.com/en/dev/ref/models/querysets/#std:fieldlookup-exact

编辑:Mysql版本是:

mysql Ver 14.14 Distrib 5.1.41, for debian-linux-gnu (i486) using readline 6.1

I have an instance of django 1.2.1 running on ubuntu with a mysql 5 backend. I am trying to make a case-sensitive query that should only return one result, but I am getting two results back that have the same content but with different cases.

I want to get an entry with the following title: Cat on the Internet syndrome

So I use the following query:

c = Change.objects.filter(change_type='new',title__exact='Cat on the Internet syndrome')

and I get the following results:

>>> c [<Change: Change object>, <Change: Change object>]

The titles of each Change object:

>>> for i in c: ... print i.title ... Cat on the Internet Syndrome Cat on the Internet syndrome

As you can see, the 'S' in syndrome within each object's title has a different case for the S in syndrome. I was under the impression from reading the documentation [0] that all queries default to the 'exact' type. I get the same results when I do not specify title__exact='Cat on the Internet syndrome'.

How do I ensure that case-sensitivity is used within the query that I outline above?

[0] http://docs.djangoproject.com/en/dev/ref/models/querysets/#std:fieldlookup-exact

Edit: Mysql version is:

mysql Ver 14.14 Distrib 5.1.41, for debian-linux-gnu (i486) using readline 6.1

最满意答案

http://code.djangoproject.com/ticket/2170

为了正确地获得功能,请更改MySql的排序规则? 数据库到latin1_swedish_cs或utf8_bin以区分大小写比较。

http://code.djangoproject.com/ticket/2170

To get the functionally correctly, change the Collation of the MySql? database to latin1_swedish_cs or utf8_bin for case sensitive comparisons.

更多推荐

本文发布于:2023-08-08 00:46:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1466655.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:多个   大小写   中对   精确   django

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!