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

馋奶兔 提交于 2019-12-11 14:45:45

问题


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'

[<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?

SOLUTION:
I solved my problem with using raw django query with adding COLLATE to sql string.

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

回答1:


Collation is a database property, so you cannot do that. Change collation to database.



来源:https://stackoverflow.com/questions/45637967/is-there-a-way-to-add-collation-in-to-django-1-3-query

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!