Note that there are some explanatory texts on larger screens.

plurals
  1. PORails App on Heroku Cannot Write to PostgreSQL Database, Only Read
    primarykey
    data
    text
    <p>I have a Ruby on Rails app that works fine locally with a sqlite3 database and can save and retrieve records without issue.</p> <p>When deployed to Heroku at <a href="http://moviedata.herokuapp.com/" rel="nofollow">http://moviedata.herokuapp.com/</a> using a postgresql database, records are not saving even though it looks like the logs say they are. Records read from the db fine and data is displayed as expected.</p> <p>The tailed logs for adding a record are:</p> <pre><code>2012-08-21T19:51:31+00:00 app[web.1]: 2012-08-21T19:51:31+00:00 app[web.1]: 2012-08-21T19:51:31+00:00 app[web.1]: Started POST "/" for 50.53.6.156 at 2012-08-21 19:51:31 +0000 2012-08-21T19:51:31+00:00 app[web.1]: Parameters: {"utf8"=&gt;"✓", "authenticity_token"=&gt;"+BYQLzhrfDkUVW8UaHikHpmtGHxpeQ/yF4VByHh9m1I=", "movie"=&gt;{"title"=&gt;"The Running Man", "description"=&gt;"A documentary about a public execution game show.", "year"=&gt;"1987", "genre"=&gt;"science fiction"}, "commit"=&gt;"Create Movie"} 2012-08-21T19:51:31+00:00 app[web.1]: Processing by MoviesController#index as HTML 2012-08-21T19:51:31+00:00 app[web.1]: Rendered movies/index.html.erb within layouts/application (5.1ms) 2012-08-21T19:51:31+00:00 app[web.1]: Completed 200 OK in 9ms (Views: 6.7ms | ActiveRecord: 0.9ms) 2012-08-21T19:51:31+00:00 heroku[router]: POST moviedata.herokuapp.com/ dyno=web.1 queue=0 wait=0ms service=17ms status=200 bytes=3479 </code></pre> <p>The 'heroku pg' command shows the same number of rows (11) on the postgres database after a record is added.</p> <p>This is a simple app I built to learn Rails and the Heroku platform. To reproduce this, just visit <a href="http://moviedata.herokuapp.com/" rel="nofollow">http://moviedata.herokuapp.com/</a> and click "New Movie", enter some junk data in the form, and hit "create movie". The record should be saved and show up in the list on the front page, but it doesn't.</p> <p>Is there perhaps something I have to turn on, configure, or activate in order to be able to write to the postgres database? Seems very strange to me that it could be read from but not written to. Any better way to troubleshoot than the logs?</p> <p>Locally I'm using Ruby 1.9.3, Rails, 3.2.8, PostgreSQL 9.1.5, SQLite 3.7.9, Heroku Toolbelt 2.30.3.</p> <p>Edit/Update: I switched the local version to use psql. It also experiences the same problem where records are not saved. With the user set to log_statement='all' The log in at /var/log/postgresql/posgresql-9.1.main.log shows lots of selects, but when the record add is attempted, the log shows the database never being hit.</p> <p>Foreman shows the data being posted, like so:</p> <pre><code>22:38:03 web.1 | Started POST "/" for 127.0.0.1 at 2012-08-21 22:38:02 -0700 22:38:03 web.1 | Processing by MoviesController#index as HTML 22:38:03 web.1 | Parameters: {"utf8"=&gt;"✓", "authenticity_token"=&gt;"0AyxRbwl/Kgi05uI1KX8uxVUJjx9ylAA1ltdWgmunm4=", "movie"=&gt;{"title"=&gt;"Army of Darkness", "description"=&gt;"A man fights the living dead using a boomstick.", "year"=&gt;"1997", "genre"=&gt;"horror"}, "commit"=&gt;"Create Movie"} 22:38:03 web.1 | Movie Load (0.8ms) SELECT "movies".* FROM "movies" ORDER BY title 22:38:03 web.1 | Rendered movies/index.html.erb within layouts/application (14.9ms) </code></pre> <p>A failed commit does sound like a great explanation. I'm not yet sure how to check whether the driver is set to commit or to see how/when a commit might have failed.</p> <p>This is a very simple application, with no load balancing or complex configuration and most of the code was generated by the 'generate scaffold' command, but it's entirely possible that there's some constraint that's being violated somewhere before the db is ever hit. Perhaps there's a way to crank the Foreman (or Rails) log level up to 11? I also tried using thin instead and scoured the log files in the log/ folder and didn't find anything other than what's logged above.</p>
    singulars
    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