Heroku:从 MySQL 迁移数据库后 Postgres 类型运算符错误

发布于 2024-09-03 18:49:49 字数 1230 浏览 2 评论 0原文

这是我之前提出的一个问题的后续问题,该问题将其表述为更多的是编程问题而不是数据库问题。

Heroku 上的 Sinatra/Haml/DataMapper 出现 Postgres 错误

我相信运行db:push后,问题已被隔离到 Heroku 的 Postgres 数据库中 ID 列的存储。

简而言之,我的应用程序在原始 MySQL 数据库上运行正常,但在 ID 列上执行任何查询时,在 Heroku 上抛出 Postgres 错误,该 ID 列似乎已作为 TEXT 存储在 Postgres 中,尽管它在 MySQL 中存储为 INT。我的问题是,为什么在将数据传输到 Heroku 时,在 Postgres 中将 ID 列创建为 INT,以及是否有任何方法可以防止这种情况发生。

以下是 heroku 控制台 会话的输出,演示了该问题:

Ruby console for myapp.heroku.com
>> Post.first.title
=> "Welcome to First!"
>> Post.first.title.class
=> String
>> Post.first.id
=> 1
>> Post.first.id.class
=> Fixnum
>> Post[1]
PostgresError: ERROR:  operator does not exist: text = integer
LINE 1: ...", "title", "created_at" FROM "posts" WHERE ("id" = 1) ORDER...
                                                         ^
HINT:  No operator matches the given name and argument type(s). You might need to add explicit type casts.
Query: SELECT "id", "name", "email", "url", "title", "created_at" FROM "posts" WHERE ("id" = 1) ORDER BY "id" LIMIT 1

谢谢!

This is a follow-up to a question I'd asked earlier which phrased this as more of a programming problem than a database problem.

Postgres error with Sinatra/Haml/DataMapper on Heroku

I believe the problem has been isolated to the storage of the ID column in Heroku's Postgres database after running db:push.

In short, my app runs properly on my original MySQL database, but throws Postgres errors on Heroku when executing any query on the ID column, which seems to have been stored in Postgres as TEXT even though it is stored as INT in MySQL. My question is why the ID column is being created as INT in Postgres on the data transfer to Heroku, and whether there's any way for me to prevent this.

Here's the output from a heroku console session which demonstrates the issue:

Ruby console for myapp.heroku.com
>> Post.first.title
=> "Welcome to First!"
>> Post.first.title.class
=> String
>> Post.first.id
=> 1
>> Post.first.id.class
=> Fixnum
>> Post[1]
PostgresError: ERROR:  operator does not exist: text = integer
LINE 1: ...", "title", "created_at" FROM "posts" WHERE ("id" = 1) ORDER...
                                                         ^
HINT:  No operator matches the given name and argument type(s). You might need to add explicit type casts.
Query: SELECT "id", "name", "email", "url", "title", "created_at" FROM "posts" WHERE ("id" = 1) ORDER BY "id" LIMIT 1

Thanks!

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

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

发布评论

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

评论(2

许你一世情深 2024-09-10 18:49:49

我在 Heroku 提出了支持请求,他们的人员能够快速为我解决这个问题。在向他们发送我的 MySQL 表架构后,他们建议我从 ID 列中删除 UNSIGNED

你能删除 UNSIGNED 位并看看是否有效吗?我认为续集不支持这一点。如果可行,我将编写续集的补丁。

完成此操作后,我就可以像以前使用 db:push 一样迁移数据库,并且该应用程序功能齐全。

Heroku 的平台和支持给我们留下了越来越深刻的印象。

I opened a support request at Heroku and their guys were able to quickly resolve this for me. After sending them my MySQL table schema, they suggested that I remove UNSIGNED from my ID columns:

Can you remove the UNSIGNED bit and see if that works? I don't think sequel supports that. If that works, I'll write a patch to sequel.

Once I did that, I was able to migrate the database the same way as before using db:push, and the app was fully functional.

Continually more impressed w/ Heroku, both for their platform and support.

时光病人 2024-09-10 18:49:49

你不能将它拉到本地 postgres 数据库吗?是否需要执行必要的 ALTER/COPY?MOVE TABLE 魔法并将其再次推回?

Can't you pull it to a local postgres database. Do the necessaery ALTER/COPY?MOVE TABLE magic and push it back again?

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