PGError: ERROR: User Relationships Don't Exist - Rails Tutorial 2nd Edition Chapter 9 Heroku

At the end of chapter 9 of the Hartl Rails tutorial (2nd Edition), an error occurred while populating db with the rake task. Ended up by resolving this, but not sure what went wrong. In case someone else hits this error, here is what I did. If anyone knows what went wrong, please comment - I would like to know. Thank!

Ran these teams

$ 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 this error happened:

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)

Failed to find out what happened. Then came across this post: Heroku Postgres error: PGError: ERROR: the "organization" relationship does not exist (ActiveRecord :: StatementInvalid)

From this, I simply executed the following commands:

heroku run rake db:reset
heroku run rake db:migrate
heroku run rake db:populate

. , SHARED_DATABASE... - , .

+3
3

. :

$ 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

@rjz

+7

, . , .

$ heroku restart
+6

If someone else encounters this, another problem arises that has the same symptom. If you have an unmigrated table that also has an AR observer that is installed in application.rb, the rake will not load because it is trying to load the base model that is being observed. You need to migrate and then add the AR observer to application.rb.

+2
source

All Articles