postgresデータベースに新しいレコードを作成する際の問題。HerokuCedarスタックとRailsの使用3.2。
createresultsを呼び出すと
ActiveRecord::RecordNotUnique (PG::Error: ERROR: duplicate key value violates unique constraint "answer_selections_pkey"
問題テーブルのスキーマは次のとおりです(暗黙の自動インクリメントID列を使用する必要があります)。
create_table "answer_selections", :force => true do |t|
t.integer "individual_id"
t.integer "answer_choice_id"
t.boolean "still_true", :default => false
end
そして、createを呼び出すときのエラーは次のとおりです。
2012-09-07T14:46:44+00:00 app[web.1]: ActiveRecord::RecordNotUnique (PG::Error: ERROR: duplicate key value violates unique constraint "answer_selections_pkey"
2012-09-07T14:46:44+00:00 app[web.1]: : INSERT INTO "answer_selections" ("answer_choice_id", "individual_id", "still_true") VALUES ($1, $2, $3) RETURNING "id"):
2012-09-07T14:46:44+00:00 app[web.1]: app/controllers/answer_selections_controller.rb:10:in `create'
同様に、別のテーブルにも同じエラーが表示されます。
2012-09-09T04:10:34+00:00 app[web.2]: ActiveRecord::RecordNotUnique (PG::Error: ERROR: duplicate key value violates unique constraint "trips_pkey"
2012-09-09T04:10:34+00:00 app[web.2]: : INSERT INTO "trips" ("booked", "created_at", "destination_id", "end_date", "individual_id", "n_travelers", "name", "start_date", "updated_at") VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9) RETURNING "id"):
接続がタイムアウトしたため、postgresデータベースに直接アクセスできません:
$ heroku pg:psql
psql: could not connect to server: Connection timed out
どうすればこれを修復できますか、また将来どのように回避できますか?VACCUUMとANALYZEを実行すると解決することを読みましたが、前述したように、psqlにアクセスできません。
編集して要求された情報を追加します(上記のサンプルスキーマ、ActiveRecordを使用しています):
@record.create(params) # How these records are created