I had a similar issue but mine DB column definition is int2, so I had to use ::smallint to cast the type.
int2
::smallint