Pat*_*ens 3 sqlite haskell yesod
UTCTime在Yesod中使用我的模型中的字段时,我收到以下错误:
PersistMarshalError "field timestamp: Expected UTCTime, received PersistText \"09:18:07\""
Run Code Online (Sandbox Code Playgroud)
我正在使用SQLite来存储我的数据库.我的模型如下:
Myobject
timestamp UTCTime default=CURRENT_TIME
otherfield Text
Run Code Online (Sandbox Code Playgroud)
请注意,使用和不使用默认值时都会发生此错误.
我正在选择Myobject-entities 列表如下:
myobjects <- selectList [] [Desc MyobjectTimestamp]
Run Code Online (Sandbox Code Playgroud)
使用MyobjectOtherfield而不是MyobjectTimestamp没有任何帮助,这是有道理的,因为所有数据都被提取并因此无论如何都被编组.
UTCTime在使用SQLite时如何在Yesod中使用?
编辑:PersistText \"09:18:07\"错误中提到的是字段默认的值.
您存储了一个Text值"09:18:07",而它期望一个UTCTime值.您是否手动插入值?
getCurrentTimefrom Data.Time返回一个类型的值IO UTCTime,因此您可以putStr getCurrentTime在GHCI中使用以获得有效的表示,或者now <- liftIO getCurrentTime在您的函数中使用.
编辑:因为getCurrentTime返回一个时间戳,如:2013-10-25 10:16:32.1627238 UTC在数据库中插入这样的值应解决错误.