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

标签 postgresql heroku datamapper taps

这是我之前提出的一个问题的后续问题,该问题更像是一个编程问题而不是数据库问题。

Postgres error with Sinatra/Haml/DataMapper on Heroku

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

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

这是演示问题的 heroku 控制台 session 的输出:

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

谢谢!

最佳答案

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

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.

一旦我这样做了,我就能够像以前一样使用 db:push 迁移数据库,并且该应用程序功能齐全。

Heroku 的平台和支持给他们留下了更深刻的印象。

关于postgresql - Heroku:从 MySQL 迁移数据库后出现 Postgres 类型运算符错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2943693/

相关文章:

python - 使用 python 在 postgres 中复制(从)带有标题的 csv

python - 不和谐机器人在哪里可以找到 ffmpeg buildpack heroku

javascript - Node JS Post 请求导致 Heroku 严重错误请求超时 (503)

ruby-on-rails - 使用 DataMapper 在 Rails 3 中保存嵌套资源表单时出现 "NoMethodError"错误

java - 数据映射器模式 : where to put a checkLogin method for a User Model?

json - jackson Json 对象映射器 : how to map an array?

postgresql - 如何使用其他表中的列/字段对 PostgreSQL 表进行集群

postgresql - 用于检查数据的 postgres 触发器

postgresql - 在 postgresql 中,如何在 char 中保留空格

python - 钢铁 worker 工作完成通知