简体   繁体   English

有没有一种方法可以将“整理”添加到Django 1.3查询中?

[英]Is there a way to add “Collation” in to Django 1.3 query?

I need to make a get query like: 我需要进行以下查询:

obj = Current.objects.get(Code='M01.C0001')

But the query giving "Multiple Objects Returned' error because of the database has another record with similar unicode string 'M01. Ç 0001' 但是由于数据库而给出“返回多个对象”错误的查询具有另一个记录,该记录具有类似的Unicode字符串“ M01。Ç0001

[<obj: M01.Ç0001>, <obj: M01.C0001>]

I try to fetch data with field lookup functions, but it does not work anyway. 我尝试使用字段查找功能来获取数据,但是仍然无法正常工作。

I googled around but I didn't find a way to temporarily set the Collation for this query. 我四处搜寻,但没有找到暂时设置此查询排序规则的方法。

Is it possible to temporarily set collation during executing a get query in Django 1.3? 是否可以在Django 1.3中执行get查询期间临时设置排序规则?

SOLUTION: 解:
I solved my problem with using raw django query with adding COLLATE to sql string. 我使用原始django查询并向SQL字符串添加COLLATE解决了我的问题。

obj = Current.objects.raw("SELECT * FROM Current WHERE Code = 'M01.C0001' COLLATE utf8_bin;")

Collation is a database property, so you cannot do that. 归类是数据库属性,因此您不能这样做。 Change collation to database. 将排序规则更改为数据库。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM