PostgreSQL is "strongly typed" - that is, every value in every query has a particular type, either defined explicitly (e.g. the type of a column in a table) or implicitly (e.g. the values input into a WHERE
clause). All functions and operators, including =
, have to be defined as accepting specific types - so, for instance there is an operator for VarChar = VarChar
, and a different one for int = int
.
In your case, you have a column which is explicitly defined as type int
, but you are comparing it against a value which PostgreSQL has interpreted as type text
.
SQLite, on the other hand, is "weakly typed" - values are freely treated as being of whatever type best suits the action being performed. So in your dev SQLite database the operation '42' = 42
can be computed just fine, where PostgreSQL would need a specific definition of VarChar = int
(or text = int
, text
being the type for unbounded strings in PostgreSQL).
Now, PostgreSQL will sometimes be helpful and automatically "cast" your values to make the types match a known operator, but more often, as the hint says, you need to do it explicitly. If you were writing the SQL yourself, an explicit type case could look like WHERE id = CAST('42' AS INT)
(or WHERE CAST(id AS text) = '42'
).
Since you're not, you need to ensure that the input you give to the query generator is an actual integer, not just a string which happens to consist of digits. I suspect this is as simple as using fields.IntegerField
rather than fields.CharField
, but I don't actually know Django, or even Python, so I thought I'd give you the background in the hope you can take it from there.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…