简体   繁体   中英

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:

some_title = "Foo"
result = Article.objects.filter(title__icontains=some_title)

articles with the title "foo" are not within the result. why? I am using Django (1.9.12).

I was using Mysql database with collation set to X_bin. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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