I use Django with Postgres as my database.
If I run this code:
SomeClass.objects.filter(text__regex=rf"searchkeyword")
the_query = str(SomeClass.query)
The the_query
variable will be this:
SELECT * FROM "SomeClass" WHERE "SomeClass "."text"::text ~ searchkeyword
But when you run this query using SomeClass.objects.raw(query)
, it will show this error:
Exception Value:
column "usa" does not exist
... WHERE "SomeClass"."text"::text ~* searchkeyword
So, basically, Django ORM can't run the raw query that it made itself.
Does anyone have any thoughts on this?
First Edit: Even for simpler queries like this, I get the same error:
SomeClass.objects.filter(text="searchkeyword")
column "searchkeyword" does not exist
LINE 1: SELECT * FROM SomeClass WHERE text = searchkeyword
Second Edit: This is a little different question than this: Printing Django QuerySet SQL with ""
In my case, even it does not work if double quotations are used and not removed.