无法将类型`BaseBackend(YesodPersistBackend PersonalPage)'与`SqlBackend'匹配

时间:2017-09-21 21:44:22

标签: haskell postgresql-9.1 yesod yesod-forms

我在使用持久性和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 }

1 个答案:

答案 0 :(得分:1)

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

instance YesodPersist App where
  type YesodPersistBackend App = SqlBackend
  runDB action = do
    master <- getYesod
    runSqlPool action $ appConnPool master