views:

1245

answers:

4

I was referred to Heroku for Ruby on Rails hosting and so far I think I am really going to like it. Just wondering if I anyone out there can help me figure out what is wrong.

I follow there instructions for creating an app on there site, create and commit git, push the code and it shows up at http://mylifebattlecry.heroku.com (though the bulk of what I have done is in the /posts/ path) When I go to enter a new "post" (because this is kind of a blog platform) I get the 500.html error and essentially everything shuts down. Can't even get back to the page that I entered the post.

Seems to me something is wrong with the database set up. I did as they suggested including ...$ heroku rake db:migrate, and nothing.

Just wondering if anyone knows off hand what I am doing wrong. Here are the instructions they give for reference:

Install the Heroku gem:sudo gem install herokuCreate a new git repository for your app (if you haven't already):

cd myapp
git init && git add . && git commit -m "first commit"

Create a new Heroku app:

heroku create
Created http://sharp-autumn-42.com/ | [email protected]:sharp-autumn-42.git
Git remote heroku added

NOTE: The app's name is generated automatically; don't worry, you can rename it at any time.

Deploy your code:

git push heroku master

Run migrations (or other bootstrap tasks):

heroku rake db:migrate

Open the deployed app in your browser: heroku open

Here is the ..$ heroku logs if it helps:

brandon-gadocis-macbook-pro:mylifebattlecry bgadoci$ heroku logs -app mylifebattlecry
==> dyno-629271.log <==

==> production.log <==
# Logfile created on Sun Nov 22 18:26:06 -0800 2009

Processing PostsController#index (for 99.7.50.140 at 2009-11-22 18:26:07) [GET]
Rendering template within layouts/posts
Rendering posts/index

ActionView::TemplateError (PGError: ERROR:  column votes.post_id does not exist
LINE 1: SELECT count(*) AS count_all FROM "votes" WHERE ("votes".pos...
                                                         ^
: SELECT count(*) AS count_all FROM "votes" WHERE ("votes".post_id = 1) ) on line #58 of app/views/posts/index.html.erb:
55:        </div>
56:       <div id="vote"><br/>
57:        <div id="votes">
58:         <%= pluralize post.votes.count, 'Person' %>  like the above BattleCry. <br/>
59:        </div>
60:        <%= link_to "Comments (#{post.comments.count})", post %>
61:       </div>

    app/views/posts/index.html.erb:58
    app/views/posts/index.html.erb:51
    app/views/posts/index.html.erb:45:in `each'
    app/views/posts/index.html.erb:45
    app/controllers/posts_controller.rb:11:in `index'
    /home/heroku_rack/lib/static_assets.rb:9:in `call'
    /home/heroku_rack/lib/last_access.rb:25:in `call'
    /home/heroku_rack/lib/date_header.rb:14:in `call'
    thin (1.0.1) lib/thin/connection.rb:80:in `pre_process'
    thin (1.0.1) lib/thin/connection.rb:78:in `catch'
    thin (1.0.1) lib/thin/connection.rb:78:in `pre_process'
    thin (1.0.1) lib/thin/connection.rb:57:in `process'
    thin (1.0.1) lib/thin/connection.rb:42:in `receive_data'
    eventmachine (0.12.6) lib/eventmachine.rb:240:in `run_machine'
    eventmachine (0.12.6) lib/eventmachine.rb:240:in `run'
    thin (1.0.1) lib/thin/backends/base.rb:57:in `start'
    thin (1.0.1) lib/thin/server.rb:150:in `start'
    thin (1.0.1) lib/thin/controllers/controller.rb:80:in `start'
    thin (1.0.1) lib/thin/runner.rb:173:in `send'
    thin (1.0.1) lib/thin/runner.rb:173:in `run_command'
    thin (1.0.1) lib/thin/runner.rb:139:in `run!'
    thin (1.0.1) bin/thin:6
    /usr/local/bin/thin:20:in `load'
    /usr/local/bin/thin:20

Rendering /disk1/home/slugs/88382_601a216_9803/mnt/public/500.html (500 Internal Server Error)
+1  A: 

Nothing wrong in the process, you could try to heroku restart to restart the app — but your best bet is to do heroku logs, right after loading the problem page, and see what it tells you.

cloudhead
I am about to update the question with what it spits out. Can't really make sense of it. Support at Heroku tried to help but didn't do a great job so far. Bascially he told me to look at the logs, then he told me that my vote table didn't have the post_id column, then to do heroku rake db:migrate, nothing worked yet. I also tried restarting the server as you mentioned but still not working.
bgadoci
This is usually the cause of this error for me. Heroku doesn't restart after you migrate, so even if you table has a column you're referencing in your code, it won't be picked up by Rails until you restart.
Luke Francl
+3  A: 

Are you sure you have migrations for all your tables.

You could do heroku rake db:schema:load to just load a fresh schema

Mike H
actually I don't...and that would explain the problem. I added the post_id simply by creating a column using Base.app which is a database interface for sqlite3. Is it as simple as just doing script/generate migration... and calling the columns the same?
bgadoci
To avoid such errors you could just use migrations to add those columns in the first place, e.g. `script/generate migration AddPostIdToVotes post_id:integer`.
Tomas Markauskas
+4  A: 

The important line in the logs is:

PGError: ERROR: column votes.post_id does not exist

This means the database on Heroku doesn't have the schema your app is trying to use.

Make sure you have a migration that creates the tables the way you want, commit the changes, then run: heroku rake db:migrate and you'll be all done.

To test, start with a clean local database (if using sqlite, just nuke db/development.sqlite3), and run rake db:migrate locally. If it works on your local machine, it should then work on Heroku.

teich
You can also `rake db:drop` to nuke it, then `rake db:create` to recreate an empty database with the correct name. You need to do this for non-sqlite databases.
nfm
A: 

I was having a similar issue. heroku restart solved the issue where heroku rake db:migrate wasn't taking. also, you can inspect your app via heroku console (./script/console on the remote app).

enure