问题描述
我需要进行以下查询:
obj = Current.objects.get(Code='M01.C0001')
但是由于数据库给出 Multiple Objects Returned错误的查询存在另一条类似的记录Unicode字符串'M01。Ç 0001'
But the query giving "Multiple Objects Returned' error because of the database has another record with similar unicode string 'M01.Ç0001'
[<obj: M01.Ç0001>, <obj: M01.C0001>]
我尝试使用字段查找功能来获取数据,但确实如此
I try to fetch data with field lookup functions, but it does not work anyway.
我在Google上四处搜寻,但没有找到临时设置此查询排序规则的方法。
I googled around but I didn't find a way to temporarily set the Collation for this query.
在Django 1.3中执行get查询期间是否可以临时设置排序规则?
Is it possible to temporarily set collation during executing a get query in Django 1.3?
解决方案:
我使用原始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.
这篇关于有没有一种方法可以添加“整理”在Django 1.3查询中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!