这是我之前提出的一个问题的后续,该问题将其表述为更多的编程问题而不是数据库问题。
Heroku 上的 Sinatra/Haml/DataMapper 出现 Postgres 错误
我相信问题已经被隔离到 Heroku 的 Postgres 数据库中 ID 列在运行后的存储中db:push
。
简而言之,我的应用程序在我的原始 MySQL 数据库上正常运行,但在对 ID 列执行任何查询时在 Heroku 上引发 Postgres 错误,这似乎已作为 TEXT 存储在 Postgres 中,即使它在 MySQL 中存储为 INT。我的问题是为什么在 Postgres 中将 ID 列创建为 INT 以将数据传输到 Heroku,以及我是否有任何方法可以防止这种情况发生。
heroku console
这是演示该问题的会话的输出:
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
谢谢!