I face a common problem. My Rails app works on my local machine, but after deploying to heroku it crashes:
<% unless @user.hotels.empty? %>
<% @user.hotels.each do |hotel| %>
<%= "#{hotel.description} #{hotel.name} in #{hotel.city}, #{hotel.country}" %><br />
<% end %>
<% end %>
This is from the heroku logs:
ActionView::Template::Error (PGError: ERROR: operator does not exist: character varying = integer
LINE 1: SELECT "hotels".* FROM "hotels" WHERE ("hotels".user_id = 1)
^
HINT: No operator matches the given name and argument type(s). You might need to add explicit type casts.
: SELECT "hotels".* FROM "hotels" WHERE ("hotels".user_id = 1)):
@user.hotels.empty?
creates the error. I know, sqlite is pretty forgiving, but PostgreSQL is not. This is the foreign key in the hotel model: user_id :integer
Heroku says:
Make sure the operator is adequate for the data type. ActiveRecord does this automatically when you use an interpolated condition form.
Array conditions:
:conditions => ['column1 = ? AND column2 = ?', value1, value2]
Hash conditions:
:conditions => { :column1 => value1, :column2 => value2 }
The migration looks like following:
class CreateHotels < ActiveRecord::Migration
def self.up
create_table :hotels do |t|
t.string :name
t.string :vanity_url
t.integer :user_id
....
This typically happens when the foreign key in the database is not an integer.
For example:
LINE 1: SELECT "hotels".* FROM "hotels" WHERE ("hotels".user_id = 1)
^
In this case, PostgreSQL expects user_id
to be an integer, but it almost looks like it's telling you that it was actually a varchar.
I would try removing the column and adding it again.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With