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

发布于 2024-10-26 23:28:35 字数 548 浏览 0 评论 0原文

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

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

有人有什么想法吗?这对我来说是第一次,特别是因为我已经在其他应用程序上使用 Heroku 工作了一年,但还没有看到这样的事情。当然,一切都可以在本地 SQLite 上运行。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(13

萌面超妹 2024-11-02 23:28:35

我也有同样的问题。要解决这个问题,重置数据库更容易。

  • 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)

然后,我的迁移已成功完成case :)

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

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

快乐很简单 2024-11-02 23:28:35

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

heroku rake db:migrate

:)

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

heroku rake db:migrate

:)

嘿哥们儿 2024-11-02 23:28:35

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

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

穿透光 2024-11-02 23:28:35

我的 Heroku 版本:

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

为了修复它,只需打开终端并运行:

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

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
新雨望断虹 2024-11-02 23:28:35

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

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.

北方的韩爷 2024-11-02 23:28:35

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

https://github。 com/plataformatec/devise/wiki/操作方法:-升级到-Devise-2.0-migration-schema-style

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

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

不乱于心 2024-11-02 23:28:35

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

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

属性 2024-11-02 23:28:35

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

一切在 SQLite 上本地运行良好,但出现相同的 PG 错误在赫罗库上。事实证明,由于类似于上述的错误,ActiveScaffold 以某种方式阻止 Heroku Push 成功运行 rake 任务。因此,如果您尝试运行 heroku rake db:migrate 或类似的命令,您会得到一个缓存 22,并且会出现相同的错误。

现在修复:

  • 注释掉使用“active_scaffold”的所有控制器中类似于以下的代码块:

    active_scaffold :<模型名称>;做 |conf|
    结尾
    
  • 提交,推送到heroku
  • heroku run rake db:migrate
  • 验证通过运行 heroku run Rails console 一切都很好,然后创建一个模型并保存它。
  • 现在恢复更改(即恢复上面的active_scaffold块)
  • 提交,推送到heroku,
  • 你就可以开始工作了!

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: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!
神回复 2024-11-02 23:28:35

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

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.

月竹挽风 2024-11-02 23:28:35
rake db:drop
rake db:create
rake db:migrate
rake db:drop
rake db:create
rake db:migrate
极度宠爱 2024-11-02 23:28:35

我遇到了类似的问题,并运行 heroku run rake db:resetheroku run rake db:migrate 来解决该问题。我想我只是没有运行正确的迁移来解决问题。

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

假装不在乎 2024-11-02 23:28:35

导致此错误的原因可能有很多。然而,对于我的应用程序,问题是我在运行迁移之前没有注销该应用程序(?)。所以走这条路:
http://name_of_my_app.herokuapp.com/logout
为我解决了问题。

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

回眸一遍 2024-11-02 23:28:35

经过几个小时的筛选答案后,我意识到,当您指定

rails new MYAPP -database POSTGRESQL

它时,它会更改 .gitignore 文件,忽略整个 /db/ 目录,因此我的数据库永远不会被推送到heroku。小心删除它,或者至少不要在你推送的地方有你的用户名和密码。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文