我有一个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.1I 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 syndromeAs 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.
更多推荐
发布评论