关联是否依赖于 Rails 中的数据库?

发布于 2024-09-29 07:02:31 字数 535 浏览 0 评论 0原文

我在 mysql 上测试了一个关联,如下所示,它有效:

User.campaigns

这些是模型中的关联:

Campaign belongs_to :user

User has_many :campaigns

但是,当我在使用 Postgres 的 Heroku 上运行它时,我得到以下信息:

CampaignsController#index (ActiveRecord::StatementInvalid) "PGError: ERROR: column campaigns.user_id does not exist\nLINE 1: SELECT * FROM \"campaigns\" WHERE (\"campaigns\".user_id = 1) \n ^\n: SELECT * FROM \"cam

这有点令人担忧,因为 -- 如果我使用的方式Rails 关联取决于数据库...嗯...不知道如何有效地进行任何开发...想法?

I tested an association on mysql as follows and it works:

User.campaigns

These are the associations in the Models:

Campaign belongs_to :user

User has_many :campaigns

However, when I run it on heroku which uses Postgres, I get the following:

CampaignsController#index (ActiveRecord::StatementInvalid) "PGError: ERROR: column campaigns.user_id does not exist\nLINE 1: SELECT * FROM \"campaigns\" WHERE (\"campaigns\".user_id = 1) \n ^\n: SELECT * FROM \"cam

This is a little worrying because -- if the way I use rails associations depends on the database...hmm...not sure how I can effectively doing any development...thoughts?

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

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

发布评论

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

评论(1

淡墨 2024-10-06 07:02:31

您的错误表明该列不存在。你在 Heroku 上运行过迁移吗?

$ heroku rake db:migrate

Your error indicates the column doesn't exist. Have you run the migrations on Heroku?

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