I recently migrated a django project from mysql to postgresql and in the process broke a filter that was being used. The old filter looked like this:
return (model_class.objects.filter(status='0',ir=1).count() * 2) +
model_class.objects.filter(status='1',ir=1).count()
However, that now produces an error that states:
DatabaseError at /report/trip/publication
operator does not exist: integer = boolean
LINE 1: ...AND "publication"."ir" = true )
^
HINT: No operator matches the given name and argument type(s).
You might need to add explicit type casts.
I’ve tried setting ir = ‘1’, and I’ve even tried setting it to ‘3’ (why the hell not?), but regardless of what I set it to, it keeps throwing the same error message, which seems to imply that something else is gunking it up. I did set it to “return None” and that gave me an unfiltered list. The only possible conflict I could see is that there is a declaration up top, but it shouldn’t be an issue (it wasn’t before):
class Publication(Unit):
ir = models.BooleanField(default=False,null=False,verbose_name="Is IR")
My postgres database has these fields with the following datatypes:
status | character varying
ir | integer
Needless to say, I am extremely confused. I didn’t set this up – I’m only trying to fix it (and learn something in the process). What is the proper way to filter this? Any feedback would be appreciated.
In Postgres, a BooleanField is of type “boolean”.
Quick fix is to change the column in Postgres.