Ruby-on-rails Heroku Postgres 错误:PGError:错误:关系“组织”不存在(ActiveRecord::StatementInvalid)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5450930/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 00:47:45  来源:igfitidea点击:

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

ruby-on-railspostgresqlherokurails-activerecord

提问by Mark

I'm having a problem deploying my Rails app to Heroku, where this error is thrown when trying to access the app:

我在将 Rails 应用程序部署到 Heroku 时遇到问题,尝试访问该应用程序时会抛出此错误:

PGError: ERROR: relation "organizations" does not exist (ActiveRecord::StatementInvalid)

PGError:错误:关系“组织”不存在(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.

有人有任何想法吗?这对我来说是第一次,特别是因为我已经在其他应用程序上使用 Heroku 工作了一年,还没有看到类似的东西。当然,一切都适用于本地 SQLite。

回答by akipponn

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)
  • heroku rake db:reset ('heroku run rake db:reset' 如果你在 cedar 上)
  • heroku rake db:migrate ('heroku run rake db:migrate' 如果你在 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

虽然在这种情况下这是一个很好的解决方案,但不要在生产中这样做。它将从您的数据库中删除所有记录

回答by Victor S

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

我遇到了同样的问题,直到我意识到我必须这样做:

heroku rake db:migrate

:)

:)

回答by a.b.d

According to my experience (Rails 3.1, Sedar stack) after running pg:resetand db:migrateyou might have to run heroku restart.

根据我运行后的经验(Rails 3.1,Sedar 堆栈)pg:resetdb:migrate您可能必须运行heroku restart.

回答by Flavio Wuensche

My heroku version:

我的heroku版本:

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

回答by Tim Fletcher

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

你在使用设计吗?升级到 2.0 时我遇到了这个确切的问题 - 您必须手动更改迁移文件。

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

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

回答by Tim Fletcher

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.

就我而言,我还必须销毁并重新创建我的应用程序。我运行了一个 rake db:migrate 迁移文件未提交,无论出于何种原因,pg:reset 不起作用。

回答by Mark

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

显然删除我的整个应用程序然后从头开始重新部署修复它。我不知道问题是什么。

回答by Greg Silcox

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.

我让我的本地设置尽可能接近生产,包括使用 postgresql 数据库,所以我在本地机器上遇到了这个问题。无论如何,我无法删除我的生产数据库。原来我的问题只是在测试中,所以我使用: rake db:test:prepare 来修复它。

回答by paneer_tikka

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:

就我而言,症状是相同的,但根本原因和补救措施却有些不同。花了几个小时在这上面。希望这篇文章可以节省其他人的时间!我在用:

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:migrateor similar.

一切都在 SQLite 本地运行良好,但在 Heroku 上出现相同的 PG 错误。事实证明,由于与上述类似的错误,ActiveScaffold 以某种方式阻止了 Heroku push 成功运行 rake 任务。所以你会得到一个缓存 22,如果你尝试运行heroku rake db:migrate或类似的,你会得到同样的错误。

Now the fix:

现在修复:

  • Comment out code blocks similar to following from allcontrollers 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 consoleand then say creating a model and saving it.
  • Now revert the changes (i.e. bring back the active_scaffoldblock above)
  • commit, push to heroku
  • you are in business!
  • 所有使用“active_scaffold”的控制器中注释掉类似于以下的代码块:

    active_scaffold :<model_name> do |conf|
    end
    
  • 提交,推送到heroku
  • heroku run rake db:migrate
  • 通过运行验证一切正常heroku run rails console,然后说创建模型并保存它。
  • 现在恢复更改(即带回active_scaffold上面的块)
  • 提交,推送到heroku
  • 你在做生意!

回答by Connor Leech

rake db:drop
rake db:create
rake db:migrate