1
我不確定這篇文章中包含什麼,因爲我真的不明白錯誤信息,所以我剛纔包含錯誤,Model.hs文件和模型。我正在使用MySQL的Yesod腳手架站點。我使用的操作系統是Ubuntu。如果您需要查看任何其他代碼,例如數據定義然後只是問。沒有Yesod,Persistent和MySQL的實例錯誤
錯誤消息:
[ 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)
感謝提前:)
編輯:由於所要求的語言。 hs文件定義La語言數據類型:
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)
何處以及如何定義「語言」類型? – Sibi
@Sibi Language是Language.hs中由我自己定義的數據類型,用於表示用戶可以在其個人資料中選擇的各種語言。它被導入到Model.hs中作爲Import.Language。 我其實並沒有想過在錯誤語言和我的數據類型之間的聯繫,我只是認爲它是包的一部分。我想我應該給我的數據類型少通用的名稱,以便他們突出一點XD –