Note that there are some explanatory texts on larger screens.

plurals
  1. POError: operator does not exist: character varying = integer
    primarykey
    data
    text
    <p>I face a common problem. My Rails app works on my local machine, but after deploying to heroku it crashes:</p> <pre><code>&lt;% unless @user.hotels.empty? %&gt; &lt;% @user.hotels.each do |hotel| %&gt; &lt;%= "#{hotel.description} #{hotel.name} in #{hotel.city}, #{hotel.country}" %&gt;&lt;br /&gt; &lt;% end %&gt; &lt;% end %&gt; </code></pre> <p>This is from the heroku logs:</p> <pre><code>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)): </code></pre> <p><code>@user.hotels.empty?</code> creates the error. I know, sqlite is pretty forgiving, but PostgreSQL is not. This is the foreign key in the hotel model: <code>user_id :integer</code></p> <p>Heroku says:</p> <pre><code>Make sure the operator is adequate for the data type. ActiveRecord does this automatically when you use an interpolated condition form. Array conditions: :conditions =&gt; ['column1 = ? AND column2 = ?', value1, value2] Hash conditions: :conditions =&gt; { :column1 =&gt; value1, :column2 =&gt; value2 } </code></pre> <p>The migration looks like following:</p> <pre><code>class CreateHotels &lt; ActiveRecord::Migration def self.up create_table :hotels do |t| t.string :name t.string :vanity_url t.integer :user_id .... </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload