Note that there are some explanatory texts on larger screens.

plurals
  1. POSinatra App on Heroku ActiveRecord::StatementInvalid: PGError: ERROR:
    primarykey
    data
    text
    <p><strong>SCENARIO:</strong><br> I currently have anapplication on Heroku that is Sinatra Application + ActiveRecord. What currently works:<br> • I am able to view static pages of my site<br> • I am able to run migrations<br> • I am able to push my local development db to my Heroku DB (heroku db:push postgres://localhost/dev)<br> • I am able to pull from the Heroku DB down to my localhost DB (heroku db:pull postgres://localhost/dev) </p> <p><strong>THE ERROR:</strong><br> When I navigate to a page that makes a simple query like:</p> <p>@pics = Picture.find(:all) </p> <p>I get this error in my log file</p> <pre><code>DEBUG -- : NoMethodError: undefined method `values' for #&lt;PGresult:0x00000002844098&gt;: SHOW client_min_messages DEBUG -- : PGError: ERROR: invalid value for parameter "client_min_messages": "" : SET client_min_messages TO '' ActiveRecord::StatementInvalid - PGError: ERROR: invalid value for parameter "client_min_messages": "" /app/.bundle/gems/ruby/1.9.1/gems/activerecord-3.1.3/lib/active_record/connection_adapters/postgresql_adapter.rb:592:in `async_exec' </code></pre> <p>At this point I'm not sure what is wrong so I decided to log onto the <code>heroku console</code> and run this command to see if my tables are in the DB </p> <pre><code>&gt; heroku console &gt; ActiveRecord::Base.connection.tables </code></pre> <p>AND I get a similar errors</p> <pre><code>ActiveRecord::StatementInvalid: PGError: ERROR: invalid value for parameter "client_min_messages": "" : SET client_min_messages TO '' /app/.bundle/gems/ruby/1.9.1/gems/activerecord-3.1.3/lib/active_record/connection_adapters/postgresql_adapter.rb:592:in `async_exec' /app/.bundle/gems/ruby/1.9.1/gems/activerecord-3.1.3/lib/active_record/connection_adapters/postgresql_adapter.rb:592:in `block in execute' /app/.bundle/gems/ruby/1.9.1/gems/activerecord-3.1.3/lib/active_record/connection_adapters/abstract_adapter.rb:244:in `block in log' /app/.bundle/gems/ruby/1.9.1/gems/activesupport-3.1.3/lib/active_support/notifications/instrumenter.rb:21:in `instrument' </code></pre> <p>Then I decided to try this in the console...</p> <p><code>&gt; ActiveRecord::Base.establish_connection</code> </p> <pre><code>&gt; ActiveRecord::AdapterNotSpecified: ActiveRecord::AdapterNotSpecified /app/.bundle/gems/ruby/1.9.1/gems/activerecord-3.1.3/lib/active_record/connection_adapters/abstract/connection_specification.rb:54:in `establish_connection' /home/heroku_rack/lib/console.rb:158:in `block (2 levels) in &lt;top (required)&gt;' /home/heroku_rack/lib/console.rb:148:in `eval' /home/heroku_rack/lib/console.rb:148:in `_eval' </code></pre> <p>At this point it would seem that I have no tables and adapter connection but how can that be when I'm able to run migrations and push and pull from the Heroku DB?</p> <hr> <h2>UPDATE 1 - NOT MUCH FURTHER ALONG BUT MORE INSIGHT</h2> <p>So I decided to start from scratch and do this over again. I seem to have made some progress but I'm stuck. At re-ran my scenario I mentioned above and succeed. So my database, migration and data are all in the DB. But my app still cannot connect to the DB. BUT what's weird is my console interaction.</p> <pre><code>&gt; heroku console &gt; ActiveRecord::Base.connection_config &gt; {:adapter=&gt;"postgresql", :database=&gt;"1e2e12e21e", :username=&gt;"1e2e12e21e", :password=&gt;"i2j3i23joo12", :host=&gt;"1e2-12e-2e1212-e2e2e1.compute-1.amazonaws.com", :port=&gt;5432, :encoding=&gt;"unicode"} </code></pre> <p><em>NOTE: I replaced the real details with this fake stuff just to illustrate</em></p> <pre><code>&gt; ActiveRecord::Base.connection_handler &gt; #&lt;ActiveRecord::ConnectionAdapters::ConnectionHandler:0x00000002f8a578 @connection_pools={"…. </code></pre> <p><em>NOTE: This a really long string but it has content</em></p> <pre><code>&gt; ActiveRecord::Base.connected? &gt; false </code></pre> <p>At this point I really don't get it? I don't get how I can keep running db migrations, keeping push and pulling data, log into Heroku Console see my <code>connection_config</code> details, BUT when I run my app internal server error. AND when I run <code>ActiveRecord::Base.connection.tables</code> in <code>heroku console</code> I get <code>ActiveRecord::StatementInvalid: PGError: ERROR: invalid value for parameter "client_min_messages": ""</code></p> <p>Any thoughts on what I could be doing wrong? </p> <h2>FINAL UPDATE</h2> <p>Here is what the problem is: Heroku support kindly pointed to me to a known issue with activerecord 3.1.3. It's a bug that should be fixed in future updates: <a href="https://github.com/rails/rails/commit/92a3c487bb0d125c437e53a7f45c31fcca97f2d9" rel="nofollow">https://github.com/rails/rails/commit/92a3c487bb0d125c437e53a7f45c31fcca97f2d9</a></p> <p>How to solve the problem: I decided to use a much lower version of activerecord in my gemfile <code>gem "activerecord", "~&gt; 3.0.9</code> and my site is up and running with no problems so far.</p> <p>Why I never tried this out before I don't know. I hope this post anyone else.</p>
    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.
    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