Heroku Postgres 错误:PGError:错误:关系“组织”不存在(ActiveRecord::StatementInvalid)
我在将 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(13)
我也有同样的问题。要解决这个问题,重置数据库更容易。
然后,我的迁移已成功完成case :)
虽然在这种情况下这是一个很好的解决方案,但不要在生产中这样做。它将删除您数据库中的所有记录
I had the same problem. To solve it, resetting the database is more easier.
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
我遇到了同样的问题,直到我意识到我必须这样做:
:)
I've had the same problem until I realized that I had to do:
:)
根据我的经验(Rails 3.1,Sedar 堆栈),运行 pg:reset 和 db:migrate 后,您可能必须运行 heroku restart 。
According to my experience (Rails 3.1, Sedar stack) after running
pg:reset
anddb:migrate
you might have to runheroku restart
.我的 Heroku 版本:
为了修复它,只需打开终端并运行:
My heroku version:
In order to fix it just open your terminal and run:
就我而言,我还必须销毁并重新创建我的应用程序。我运行了 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.
你在使用设备吗?升级到 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
显然删除我的整个应用程序,然后从头开始重新部署修复了它。我不知道问题是什么。
Apparently deleting my entire app and then redeploying from scratch fixed it. I have no idea what the problem was.
就我而言,症状是相同的,但根本原因和补救措施却有所不同。花了几个小时在这上面。希望这篇文章能够节省其他人的时间!
我正在使用:
一切在 SQLite 上本地运行良好,但出现相同的 PG 错误在赫罗库上。事实证明,由于类似于上述的错误,ActiveScaffold 以某种方式阻止 Heroku Push 成功运行 rake 任务。因此,如果您尝试运行 heroku rake db:migrate 或类似的命令,您会得到一个缓存 22,并且会出现相同的错误。
现在修复:
注释掉使用“active_scaffold”的所有控制器中类似于以下的代码块:
heroku run rake db:migrate
heroku run Rails console
一切都很好,然后创建一个模型并保存它。active_scaffold
块)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":
heroku run rake db:migrate
heroku run rails console
and then say creating a model and saving it.active_scaffold
block above)我使本地设置尽可能接近生产环境,包括使用 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.
我遇到了类似的问题,并运行
heroku run rake db:reset
和heroku run rake db:migrate
来解决该问题。我想我只是没有运行正确的迁移来解决问题。I had a similar issue and ran
heroku run rake db:reset
andheroku run rake db:migrate
to fix the issue. I guess that I just hadn't run the proper migrations to fix the problem.导致此错误的原因可能有很多。然而,对于我的应用程序,问题是我在运行迁移之前没有注销该应用程序(?)。所以走这条路:
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.
经过几个小时的筛选答案后,我意识到,当您指定
它时,它会更改 .gitignore 文件,忽略整个
/db/ 目录
,因此我的数据库永远不会被推送到heroku。小心删除它,或者至少不要在你推送的地方有你的用户名和密码。After hours of sifting through answer, I realized that when you specify
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.