PGError: ERROR: relation "users" does not exist - Rails Tutorial 2nd Edition Chapter 9 Heroku
heroku, pg, railstutorial.org, ruby-on-rails-3.2
Solution
You have the steps out of order. They should be:
$ git push heroku
$ heroku pg:reset SHARED_DATABASE --confirm <name-heroku-gave-to-your-app>
$ heroku run rake db:migrate
$ heroku run rake db:populate
Hat Tip to @rjz
Problem
At end of Chapter 9 of Hartl's Rails Tutorial (2nd Edition) ran into an error when populating the db using a rake task. Ended up resolving it, but not sure what went wrong. In case anyone else hits this error, here's what I did. If anyone knows what went wrong, please comment --I'd love to know. Thanks! Ran these commands ``` $ git push heroku $ heroku run rake db:migrate $ heroku pg:reset SHARED_DATABASE --confirm <name-heroku-gave-to-your-app> $ heroku run rake db:populate ``` Then, got this error: ``` rake aborted! PGError: ERROR: relation "users" does not exist : SELECT a.attname, format_type(a.atttypid, a.atttypmod), d.adsrc, a.attnotnull FROM pg_attribute a LEFT JOIN pg_attrdef d ON a.attrelid = d.adrelid AND a.attnum = d.adnum WHERE a.attrelid = '"users"'::regclass AND a.attnum > 0 AND NOT a.attisdropped ORDER BY a.attnum Tasks: TOP => db:populate (See full trace by running task with --trace) ``` Couldn't figure out what was wrong. Then came across this post: Heroku Postgres Error: PGError: ERROR: relation "organizations" does not exist (ActiveRecord::StatementInvalid) From that, I just ran these commands: ``` heroku run rake db:reset heroku run rake db:migrate heroku run rake db:populate ``` Now the app is working. Still not clear to me why I got that error when resetting SHARED_DATABASE ... If anyone knows, curious to find out.