Heroku Postgres Error: PGError: ERROR: relation "organizations" does not exist (ActiveRecord::StatementInvalid)
Solution 1
I had the same problem. To solve it, resetting the database is more easier.
- heroku rake db:reset ('heroku run rake db:reset' if you're on cedar)
- heroku rake db:migrate ('heroku run rake db:migrate' if you're on cedar)
Then, migration was done successfully for my case :)
While this is a good solution in this context, don't do it on production. It will delete all the records from your database
Solution 2
I've had the same problem until I realized that I had to do:
heroku rake db:migrate
:)
Solution 3
According to my experience (Rails 3.1, Sedar stack) after running pg:reset
and db:migrate
you might have to run heroku restart
.
Solution 4
My heroku version:
heroku --version
#=> heroku-gem/2.29.0 (x86_64-linux) ruby/1.9.3
In order to fix it just open your terminal and run:
heroku pg:reset DATABASE --confirm YOUR_APP_NAME
heroku run rake db:setup
heroku restart
heroku open
Solution 5
In my case, I also had to destroy and recreate my app. I had run a rake db:migrate with a migration file not committed and for whatever reason, the pg:reset wasn't working.
Related videos on Youtube
Mark
Web Designer/Developer since 1998, Rails Developer since 2006
Updated on November 27, 2020Comments
-
Mark over 3 years
I'm having a problem deploying my Rails app to Heroku, where this error is thrown when trying to access the app:
PGError: ERROR: relation "organizations" does not exist (ActiveRecord::StatementInvalid)
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 = '"organizations"'::regclass AND a.attnum > 0 AND NOT a.attisdropped ORDER BY a.attnum
Anybody have any ideas? This is a first for me, especially because I've been working with Heroku for a year on other apps, and haven't see anything like this. Of course, everything works on local SQLite.
-
Shreyas about 13 yearsThe organizations table doesn't seem to exist. did you run your migration?
-
Mark about 13 yearsThanks @shreyas, yes, the migration was run, and this is the output: == CreateOrganizations: migrating ============================================ -- create_table(:organizations) -> 0.0175s -- add_index(:organizations, [:organization_type], {:name=>"organizations_index"}) -> 0.0054s == CreateOrganizations: migrated (0.0238s) ===================================
-
Mark about 13 yearsAlso, when I log into the console and check: >> ActiveRecord::Base.connection.tables => ["schema_migrations", "jobs", "organizations", etc...
-
Shreyas about 13 yearsNow that you have your organizations table created, are you still facing a problem?
-
Mark about 13 yearsYes, the organizations table was already created when the problem occurred, thanks...
-
-
Chris Cummings over 12 yearsI fought with Heroku for a good forty minutes before I thought to try this. Redeploying, dropping(reset) and migrating the database solved nothing.
-
TimD over 12 yearsIF you're running a Cedar app, the commands need to be:
heroku run rake db:reset
heroku run rake db:migrate
Thenheroku restart
and it should be fixed. -
Spidy about 12 years@TimD I'm running a Cedar app and the run is not required
-
imderek over 11 yearsThis is not the most effective solution. The other more highly rated answers are superior.
-
Connor Leech over 10 yearsI had to
rake db:drop
and thenrake db:create
also -
mariowise almost 10 yearsAnd on the production database ?? You can't reset and lose data ¿?