1

PG::UndefinedTable: ERROR

I am trying to deploy a Rails 4 app on Heroku with a postgres database. I have precompiled assets, but now when I run:

heroku run rake db:migrate

I get this error:

PG::UndefinedTable: ERROR:  relation "users" does not exist
: ALTER TABLE "users" ADD COLUMN "invited_by_user_id" integer
rake aborted!

Commonly suggested solutions on Stack Overflow:

I have tried resetting the database with:

heroku pg:reset

The database resets, but I still can't run db:migrate.

I have also tried:

heroku run db:setup

but I get an error that says:

FATAL:  permission denied for database "postgres"
DETAIL:  User does not have CONNECT privilege.

I was using Rails 4.1.8, and saw this question which suggested maybe I needed to update to rails 4.1.9 or above, but even now that I'm using Rails 4.2.2, no luck.

Additional possibly relevant info:

Connecting to the postgres database on heroku with

heroku pg:psql

then listing the databases with '\l' gives me a long list of databases with cryptic names:

 Name      |     Owner      | Encoding |   Collate   |    Ctype    |         Access privileges         
----------------+----------------+----------+-------------+-------------+-----------------------------------
 d100o5a2gii5he | rdxtahlqikernc | UTF8     | en_US.UTF-8 | en_US.UTF-8 | rdxtahlqikernc=CTc/rdxtahlqikernc
 d102ehvv3umqam | ibuffadisyolrb | UTF8     | en_US.UTF-8 | en_US.UTF-8 | ibuffadisyolrb=CTc/ibuffadisyolrb
 d103n2kea6j5sa | tzzkfcinullytw | UTF8     | en_US.UTF-8 | en_US.UTF-8 | tzzkfcinullytw=CTc/tzzkfcinullytw
 d10597iiu347nk | eltovdzaxajtiu | UTF8     | en_US.UTF-8 | en_US.UTF-8 | eltovdzaxajtiu=CTc/eltovdzaxajtiu
 d108g0imdgn865 | pvzysfivyhcnaa | UTF8     | en_US.UTF-8 | en_US.UTF-8 | pvzysfivyhcnaa=CTc/pvzysfivyhcnaa
...

 dvs2j8tkv153m  | zjefhzzizozpwy | UTF8     | en_US.UTF-8 | en_US.UTF-8 | zjefhzzizozpwy=CTc/zjefhzzizozpwy
 postgres       | postgres       | UTF8     | en_US.UTF-8 | en_US.UTF-8 | postgres=CTc/postgres
 template0      | postgres       | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres                      +
        |                |          |             |             | postgres=CTc/postgres
 template1      | postgres       | UTF8     | en_US.UTF-8 | en_US.UTF-8 | postgres=CTc/postgres
(4787 rows)

I'm not sure exactly how to interpret that.

I am relatively new new to Rails, but have successfully setup several databases on Heroku in the past. Following the Heroku documentation hasn't helped, and I'm not sure where to go from here.

How can I get db:migrate to complete without errors?

NOTE: I solved this just after posting. See answer below.

4
  • You need to add invited_by_user_id to users table Commented Jun 23, 2015 at 20:24
  • I already have a column in my users table for invited_by_user_id Commented Jun 23, 2015 at 20:26
  • Can we see your migration for the users table? Commented Jun 23, 2015 at 20:28
  • Apologies...I figured it out! I need to run db:schema:load, but for some reason couldn't do it until I upgraded to 4.2.2. Commented Jun 23, 2015 at 20:36

1 Answer 1

1

Minutes after posting this question I figured it out, and I'm hoping this might help someone else out.

The solution was to upgrade from Rails 4.1.8 to Rails 4.2.2.

Then run

heroku run rake db:schema:load

before

heroku run rake db:migrate

For some reason that wouldn't run for my project with Rails 4.1.8. So, after upgrading to Rails 4.2.2, I ran the schema load and migrate commands with no errors.

Sign up to request clarification or add additional context in comments.

1 Comment

3 sleepless nights, hours of debugging, resetting database more than 10 times. Just to find this answer. Sir , you are my savior. I salute you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.