No Instance Error with Yesod, Persistent and MySQL

330 Views Asked by At

I'm not sure what to include in this post because I really don't understand the error message so I've just included the error, the Model.hs file and the models. I'm using the Yesod scaffolding site for MySQL. The operating system I'm using is Ubuntu. If you need to see any of the other code e.g. data definitions then just ask.

Error Message:

[ 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")

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)

Thanks in advance :)

EDIT: As requested the Language.hs file defining the Language data type:

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)
1

There are 1 best solutions below

1
On BEST ANSWER

The error shows that it's not able to find the sum type related Persistent instance. You have to do two things to fix it:

=> Make sure to derive Show and Read instances for your sum type. Example:

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

=> Derive the persistent related instances for it using template haskell:

derivePersistField "Language"

You have to do this for all your sum types you are using it for your model.