yesodweb / yesodweb/persistent
Can't use `id` in Primary definition
Nobody has claimed this yet.
- Dominant language
- Haskell
- Stars
- 486
- Forks
- 306
- PR merge metrics
- No merged PRs in 30d
Description
This occurs with persistent-2.2.4.1, on the latest version of Stackage. It also occurs on 2.5.1.6.
Given the entity definition:
share [mkPersist sqlSettings] [persistLowerCase|
Foo
name String
Primary id name
|]
I get the error:
Exception when trying to run compile-time code:
Unknown column in primary key constraint: "id"
Code: template-haskell-2.10.0.0:Language.Haskell.TH.Quote.quoteExp
persistLowerCase
"\n\
\\n\
\Foo\n\
\ name String\n\
\ Primary id name\n"
If I add an explicit id column:
share [mkPersist sqlSettings] [persistLowerCase|
Foo
id Int
name String
Primary id namek
|]
Then I get this error:
/home/matt/Projects/persistent-repro/src/Lib.hs:17:1:
Multiple declarations of ‘FooId’
Declared at: src/Lib.hs:17:1
src/Lib.hs:17:1
If I use the uppercase Id syntax:
share [mkPersist sqlSettings] [persistLowerCase|
Foo
Id Int
name String
Primary Id name
|]
then we're back to this error:
Exception when trying to run compile-time code:
Unknown column in primary key constraint: "Id"
Code: template-haskell-2.10.0.0:Language.Haskell.TH.Quote.quoteExp
persistLowerCase
"\n\
\Foo\n\
\ Id Int\n\
\ name String\n\
\ Primary Id name\n"
Omitting the Id Int declaration doesn't alter the previous error.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the examples with the persistLowerCase quasiquoter and mkPersist sqlSettings, then trace how Primary definitions and implicit or explicit Id fields are parsed. Compare the handling of the id and name references to identify why the primary-key column is reported as unknown or generated twice. Done means the reported Primary definition compiles without either error and the behavior is covered by an appropriate regression test.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- haskell
- Domain
- databases
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100