gpt4 book ai didi

mysql - Yesod、Persistent 和 MySQL 没有实例错误

转载 作者:行者123 更新时间:2023-12-01 12:18:54 25 4
gpt4 key购买 nike

我不确定这篇文章要包含什么,因为我真的不明白错误消息,所以我只包含了错误、Model.hs 文件和模型。我正在为 MySQL 使用 Yesod 脚手架站点。我使用的操作系统是 Ubuntu。如果您需要查看任何其他代码,例如数据定义然后只是询问。

错误信息:

[ 6 of 20] Compiling Model            ( src/Model.hs, .stack-work/dist/x86_64-linux/Cabal-1.24.2.0/build/Model.o )

/home/james/ConVoke/convoke-website/src/Model.hs:24:7: error:
• No instance for (persistent-2.7.0:Database.Persist.Sql.Class.PersistFieldSql
Language)
arising from a use of ‘persistent-2.7.0:Database.Persist.Sql.Class.sqlType’
• In the fourth argument of ‘FieldDef’, namely
‘persistent-2.7.0:Database.Persist.Sql.Class.sqlType
(Data.Proxy.Proxy :: Data.Proxy.Proxy Language)’
In the expression:
FieldDef
(HaskellName (packPTH "language"))
(DBName (packPTH "language"))
(FTTypeCon Nothing (packPTH "Language"))
(persistent-2.7.0:Database.Persist.Sql.Class.sqlType
(Data.Proxy.Proxy :: Data.Proxy.Proxy Language))
[]
True
NoReference
In the ‘entityFields’ field of a record

-- While building package website-0.0.0 using:
/home/james/.stack/setup-exe-cache/x86_64-linux/Cabal-simple_mPHDZzAJ_1.24.2.0_ghc-8.0.2 --builddir=.stack-work/dist/x86_64-linux/Cabal-1.24.2.0 build lib:website --ghc-options " -ddump-hi -ddump-to-file"

模型.hs:
{-# LANGUAGE EmptyDataDecls             #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeFamilies #-}
module Model where

import ClassyPrelude.Yesod
import Database.Persist.Quasi

import Import.Game
import Import.Language
import Import.Profile

-- You can define all of your database entities in the entities file.
-- You can find more information on persistent and how to declare entities
-- at:
-- http://www.yesodweb.com/book/persistent/
share [mkPersist sqlSettings, mkMigrate "migrateAll"]
$(persistFileWith lowerCaseSettings "config/models")

楷模:
Player
name Text
username Text
dob Day
language Language
tournaments [TournamentResult]
deriving (Show)

PlatformAccount
player PlayerId
platform Platform
account Text
deriving (Show)

SocialAccount
player PlayerId
site SocialSite
account Text
deriving (Show)

PastTeam
player PlayerId
team TeamId
yearJoined Int
yearLeft Int
deriving (Show)

TournamentResult
player PlayerId
team TeamId
name Text
placing Text
year Int
deriving (Show)

Roster
name Text
game Game
team TeamId
players [PlayerId]
creationDay Day
deriving (Show)

PlayerRole
roster RosterId
player PlayerId
role Role
deriving (Show)

CompetitiveGame
game Game
platform Platform
role Role
availability Availability
playingSince Int
deriving (Show)

Team
name Text
creationDay Day
deriving (Show)

提前致谢 :)

编辑:根据要求定义语言数据类型的 Language.hs 文件:
module Import.Language where

allLanguages :: [Language]
allLanguages = [Afrikanns ..]

data Language = Afrikanns |
Albanian |
Arabic |
Armenian |
Basque |
Bengali |
Bulgarian |
Catalan |
Cambodian |
Chinese_Mandarin |
Croation |
Czech |
Danish |
Dutch |
English |
Estonian |
Fiji |
Finnish |
French |
Georgian |
German |
Greek |
Gujarati |
Hebrew |
Hindi |
Hungarian |
Icelandic |
Indonesian |
Irish |
Italian |
Japanese |
Javanese |
Korean |
Latin |
Latvian |
Lithuanian |
Macedonian |
Malay |
Malayalam |
Maltese |
Maori |
Marathi |
Mongolian |
Nepali |
Norwegian |
Persian |
Polish |
Portuguese |
Punjabi |
Quechua |
Romanian |
Russian |
Samoan |
Serbian |
Slovak |
Slovenian |
Spanish |
Swahili |
Swedish |
Tamil |
Tatar |
Telugu |
Thai |
Tibetan |
Tonga |
Turkish |
Ukranian |
Urdu |
Uzbek |
Vietnamese |
Welsh |
Xhosa
deriving (Enum, Show, Eq)

最佳答案

该错误表明它无法找到与总和类型相关的 Persistent 实例。你必须做两件事来修复它:

=> 确保导出 ShowRead求和类型的实例。例子:

data Language = JS | Haskell deriving (Eq, Show, Read, Ord)

=> 使用模板 haskell 为其派生持久相关实例:
derivePersistField "Language"

您必须对用于模型的所有总和类型执行此操作。

关于mysql - Yesod、Persistent 和 MySQL 没有实例错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46019916/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com