Rails 3.1. Heroku PGError: operator does not exist: character varying = integer
Your problem is here:
WHERE "reviews"."trip_id" = 32
and the error message says that:
operator does not exist: character varying = integer
so you have created your trip_id
column in reviews
as a string rather than as an integer. That will work fine in SQLite because SQLite's type system is rather loose but it won't work in PostgreSQL as PostgreSQL is quite a bit stricter.
You could try adding a migration to fix the type of trip_id
:
def change change_column :reviews, :trip_id, :integerend
and if that doesn't work then drop and recreate the table:
def change drop_table :reviews create_table :reviews do |t| #... t.integer :trip_id #... endend
You could also do an ALTER TABLE through raw SQL if you have data that you want to preserve and the change_column
doesn't work:
def change execute %q{ alter table reviews alter column trip_id type int using cast(trip_id as int) }end
That should work in PostgreSQL (but not SQLite) as long as you don't have any broken data in your trip_id
.
Once you have that sorted out, you should install PostgreSQL and switch your development environment to that. Developing on top of SQLite and deploying to PostgreSQL (or developing on top of one database and deploying on top of any other database for that matter) is a bad idea and will cause you all sorts of grief and confusion.
You could leave the column as a text/varchar data type, and cast it as an integer...
WHERE "reviews"."trip_id"::int = 32
A simpler way to do the migration is this:
change_column :reviews, :trip_id, 'integer USING CAST(trip_id AS integer)'