我不确定该帖子中包含哪些内容,因为我真的不理解错误消息所以我只是包含了错误,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"
Model.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)
答案 0 :(得分:3)
错误显示它无法找到与sum类型相关的和型实例。你必须做两件事来解决它:
=>确保为您的总和类型派生Show
和Read
个实例。例如:
data Language = JS | Haskell deriving (Eq, Show, Read, Ord)
=>使用模板haskell:
为其导出持久性相关实例derivePersistField "Language"
您必须对您为模型使用它的所有总和类型执行此操作。