0

我在 postgresql 中使用持久性和 Yesod 时遇到问题。这是带来问题的功能:

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 }
4

1 回答 1

1

您缺少相关YesodPerist实例。它会是这样的:

instance YesodPersist App where
  type YesodPersistBackend App = SqlBackend
  runDB action = do
    master <- getYesod
    runSqlPool action $ appConnPool master
于 2017-09-23T06:16:28.573 回答