无法将类型“BaseBackend(YesodPersistBackend PersonalPage)”与“SqlBackend”匹配
Couldn't match type `BaseBackend(YesodPersistBackend PersonalPage)' with `SqlBackend'
我在将 persistent 和 Yesod 与 postgresql 一起使用时遇到问题。这是带来问题的功能:
postBlogR :: MyHandler Html
postBlogR = do
((res, widgetForm), enctype) <- runFormPost blogForm
case res of
FormSuccess blog -> do
blogId <- runDB $ insert blog
redirect $ HomeR
_ -> adminLayout [whamlet|<h1>Post Created!|]
跟踪是:
* Couldn't match type `BaseBackend(YesodPersistBackend PersonalPage)'
with `SqlBackend'
arising from a use of `insert'
* In the second argument of `($)', namely `insert blog'
In a stmt of a 'do' block: blogId <- runDB $ insert blog
In the expression:
do { blogId <- runDB $ insert blog;
redirect $ HomeR }
您缺少相关的 YesodPerist
实例。它将是这样的:
instance YesodPersist App where
type YesodPersistBackend App = SqlBackend
runDB action = do
master <- getYesod
runSqlPool action $ appConnPool master
我在将 persistent 和 Yesod 与 postgresql 一起使用时遇到问题。这是带来问题的功能:
postBlogR :: MyHandler Html
postBlogR = do
((res, widgetForm), enctype) <- runFormPost blogForm
case res of
FormSuccess blog -> do
blogId <- runDB $ insert blog
redirect $ HomeR
_ -> adminLayout [whamlet|<h1>Post Created!|]
跟踪是:
* Couldn't match type `BaseBackend(YesodPersistBackend PersonalPage)'
with `SqlBackend'
arising from a use of `insert'
* In the second argument of `($)', namely `insert blog'
In a stmt of a 'do' block: blogId <- runDB $ insert blog
In the expression:
do { blogId <- runDB $ insert blog;
redirect $ HomeR }
您缺少相关的 YesodPerist
实例。它将是这样的:
instance YesodPersist App where
type YesodPersistBackend App = SqlBackend
runDB action = do
master <- getYesod
runSqlPool action $ appConnPool master