[ACCEPTED]-Heroku Postgres Error: PGError: ERROR: relation "organizations" does not exist (ActiveRecord::StatementInvalid)-rails-activerecord

Accepted answer
Score: 83

I had the same problem. To solve it, resetting 2 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 1 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

Score: 21

I've had the same problem until I realized 1 that I had to do:

heroku rake db:migrate

:)

Score: 19

According to my experience (Rails 3.1, Sedar 2 stack) after running pg:reset and db:migrate you might have 1 to run heroku restart.

Score: 7

My heroku version:

heroku --version
#=> heroku-gem/2.29.0 (x86_64-linux) ruby/1.9.3

In order to fix it just 1 open your terminal and run:

heroku pg:reset DATABASE --confirm YOUR_APP_NAME
heroku run rake db:setup
heroku restart
heroku open
Score: 1

In my case, I also had to destroy and recreate 3 my app. I had run a rake db:migrate with 2 a migration file not committed and for whatever 1 reason, the pg:reset wasn't working.

Score: 1

Are you using devise? I had this exact issue 2 when upgrading to 2.0 - You have to manually 1 change the migration file.

https://github.com/plataformatec/devise/wiki/How-To:-Upgrade-to-Devise-2.0-migration-schema-style

Score: 0

Apparently deleting my entire app and then 2 redeploying from scratch fixed it. I have 1 no idea what the problem was.

Score: 0

In my case, the symptoms were the same, but 13 the root cause and remedy turned out somewhat 12 different. Spent hours on this. Hopefully 11 this post will save someone else those hours! I 10 am using:

Everything runs fine locally on 9 SQLite, but get the same PG error on Heroku. Turns 8 out that ActiveScaffold somehow prevents 7 Heroku push from successfully running rake 6 tasks due to an error similar to above. So 5 you get a cache 22 where you get the same 4 error if you try to run heroku rake db:migrate or similar.

Now 3 the fix:

  • Comment out code blocks similar 2 to following from all controllers that use 1 "active_scaffold":

    active_scaffold :<model_name> do |conf|
    end
    
  • Commit, push to heroku
  • heroku run rake db:migrate
  • Verify that everything is fine by running heroku run rails console and then say creating a model and saving it.
  • Now revert the changes (i.e. bring back the active_scaffold block above)
  • commit, push to heroku
  • you are in business!
Score: 0

I keep my local setup as close to production 6 as possible, including using a postgresql 5 database, so I had this problem on my local 4 machine. I can't delete my production database 3 anyway. It turned out my issue was only 2 in test, so I used: rake db:test:prepare 1 to fix it.

Score: 0
rake db:drop
rake db:create
rake db:migrate

0

Score: 0

After hours of sifting through answer, I 6 realized that when you specify

rails new MYAPP -database POSTGRESQL

it changes 5 the .gitignore file, ignoring the entire 4 /db/ directory, so my database was never getting pushed 3 up to heroku. Remove it with caution, or 2 at least don't have your username and password 1 in there where you push up.

Score: 0

I had a similar issue and ran heroku run rake db:reset and heroku run rake db:migrate to fix 2 the issue. I guess that I just hadn't run 1 the proper migrations to fix the problem.

Score: 0

There may be many reasons for this error. For 4 my app, however, the issue was that I hadn't 3 logged out of the app before I ran the migration 2 (?). So going to this path: http://name_of_my_app.herokuapp.com/logout fixed the 1 problem for me.

More Related questions