これは、これをデータベースの問題というよりもプログラミングの問題として表現した以前の質問へのフォローアップです。
Heroku の Sinatra/Haml/DataMapper での Postgres エラー
問題は、実行後の Heroku の Postgres データベースの ID 列のストレージに切り分けられたと思いますdb:push
。
要するに、私のアプリは元の MySQL データベースでは適切に実行されますが、MySQL では INT として格納されているにもかかわらず、Postgres に TEXT として格納されているように見える ID 列でクエリを実行すると、Heroku で Postgres エラーがスローされます。私の質問は、Heroku へのデータ転送時に Postgres で ID 列が INT として作成されている理由と、これを防ぐ方法があるかどうかです。
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
ありがとう!