Heroku Postgres Error: PGError: ERROR: relation “organizations” does not exist (ActiveRecord::StatementInvalid)

后端 未结 13 536
有刺的猬
有刺的猬 2020-11-27 14:27

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 \"organiz

相关标签:
13条回答
  • 2020-11-27 14:50

    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

    0 讨论(0)
  • 2020-11-27 14:51

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

    0 讨论(0)
  • 2020-11-27 14:54

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

    heroku rake db:migrate
    

    :)

    0 讨论(0)
  • 2020-11-27 14:54

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

    • Heroku Cedar
    • Rails 3.2
    • ActiceScaffold Gem

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

    Now the fix:

    • Comment out code blocks similar to following from all controllers that use "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!
    0 讨论(0)
  • 2020-11-27 14:57
    rake db:drop
    rake db:create
    rake db:migrate
    
    0 讨论(0)
  • 2020-11-27 14:59

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

    rails new MYAPP -database POSTGRESQL
    

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

    0 讨论(0)
提交回复
热议问题