While using a UTCTime
field in my model in Yesod, I get the following error:
PersistMarshalError "field timestamp: Expected UTCTime, received PersistText \"09:18:07\""
I am using SQLite to store my database. My model looks as follows:
Myobject
timestamp UTCTime default=CURRENT_TIME
otherfield Text
Note that this error occurs both with and without the default value.
I am selecting the list of Myobject
-entities as follows:
myobjects <- selectList [] [Desc MyobjectTimestamp]
Using MyobjectOtherfield
instead of MyobjectTimestamp
does not help either, which makes sense since all data is fetched and therefore marshaled anyway.
A similar question has been asked here, but the answer did not help me.
How can I use UTCTime
in Yesod while using SQLite?
Edit:
The PersistText \"09:18:07\"
that is mentioned in the error is the value the field defaulted to.
You stored a Text value "09:18:07"
, while it expected a UTCTime value. Did you insert values by hand?
getCurrentTime
from Data.Time
returns a value of type IO UTCTime
, so you can either use putStr getCurrentTime
in GHCI to get a valid representation, or use now <- liftIO getCurrentTime
in your function.
EDIT:
Because getCurrentTime
returns a timestamp like: 2013-10-25 10:16:32.1627238 UTC
, inserting a value like that in your database should resolve the error.