2016-06-29 74 views
0

我已經搜索過,因此我找到了關於錯誤的答案,但是我的問題有點不同。我有這樣的錯誤:ActiveRecord插入返回PG :: DatetimeFieldOverflow錯誤

PG::DatetimeFieldOverflow: ERROR: date/time field value out of range: "24/05/2016 17:00" 
HINT: Perhaps you need a different "datestyle" setting. 

如果我查看日誌

pry(#<WebexSync::Sync>)> attributes 
    => {:webex_external_id=>1025, :user_id=>2565, :lesson_times=>[2016-05-24 17:00:00 +0200], :status=>"invited"} 

pry(#<WebexSync::Sync>)> UserWebex.create! attributes 
    User Load (1.4ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT 1 [["id", 2565]] 
    Webex Load (0.6ms) SELECT "webexes".* FROM "webexes" WHERE "webexes"."external_id" = $1 ORDER BY "webexes"."start_date" DESC LIMIT 1 [["external_id", 1025]] 
    UserWebex Exists (0.5ms) SELECT 1 AS one FROM "user_webexes" WHERE ("user_webexes"."user_id" = 2565 AND "user_webexes"."webex_external_id" = 1025) LIMIT 1 
    SQL (2.3ms) INSERT INTO "user_webexes" ("webex_external_id", "user_id", "lesson_times", "status") VALUES ($1, $2, $3, $4) RETURNING "id" [["webex_external_id", 1025], ["user_id", 2565], ["lesson_times", "{24/05/2016 17:00}"], ["status", "invited"]] 
PG::DatetimeFieldOverflow: ERROR: date/time field value out of range: "24/05/2016 17:00" 
HINT: Perhaps you need a different "datestyle" setting. 
: INSERT INTO "user_webexes" ("webex_external_id", "user_id", "lesson_times", "status") VALUES ($1, $2, $3, $4) RETURNING "id" 
ActiveRecord::StatementInvalid: PG::DatetimeFieldOverflow: ERROR: date/time field value out of range: "24/05/2016 17:00" 
HINT: Perhaps you need a different "datestyle" setting. 

我想不通爲什麼我的對象PARAMS都OK,和日期的格式如下[2016-05-24 17:00:00 +0200],但同時節省ActiveRecord的改變在["lesson_times", "{24/05/2016 17:00}"]

lesson_times格式是一個數組

回答

0

由於錯誤說:HINT: Perhaps you need a different "datestyle" setting. ,這是相當正確的。

以下是如何在PG中設置不同的datestyle

SET datestyle = "ISO, DMY"; 
+0

好吧,但這是一個巨大的應用程序,爲什麼我只在這個插入這個問題? –

+0

可能是您試圖放置的日期格式不正確。嘗試其他格式。 –

相關問題