[英]Why filtering django with icontains is case sensitive?
I want to filter a queryset with icontains because I don't want the filtration to be case sensitive: 我想用icontains过滤查询集,因为我不希望过滤区分大小写:
some_title = "Foo"
result = Article.objects.filter(title__icontains=some_title)
articles with the title "foo" are not within the result. 标题为“ foo”的文章不在结果之内。 why?
为什么? I am using Django (1.9.12).
我正在使用Django(1.9.12)。
I was using Mysql database with collation set to X_bin. 我使用排序规则设置为X_bin的Mysql数据库。 I changed the collation of the article table with:
我用以下方式更改了商品表的排序规则:
ALTER TABLE articles CHARACTER SET utf8 COLLATE utf8_general_ci;
to apply to all columns: 应用于所有列:
ALTER TABLE articles CONVERT TO CHARACTER SET utf8;
somehow the old collation uses another method of string comparison that does'nt respect letter case. 旧排序规则以某种方式使用了另一种不考虑字母大小写的字符串比较方法。 the new collation utf8_general_ci does.
新的排序规则utf8_general_ci可以。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.