Error parsing attribute "@relation" when unique/id index is in different order
See original GitHub issueBug description
The Prisma model will not generate if there is a valid key whose columns are in a different order than it expects them.
How to reproduce
- Create a model from the template below
- See the file and observe the highlighted error
Expected behavior
It should work.
Prisma information
model nabzak {
offerID Int @db.UnsignedSmallInt
periodID Int @db.UnsignedSmallInt
carrierID Int
reservation String? @db.Char(2)
wanted Int? @db.TinyInt
carrierInPeriod CarrierInPeriod @relation(fields: [offerID, periodID, carrierID], references: [offerID, periodID, carrierID], onDelete: Cascade, onUpdate: NoAction)
@@id([offerID, carrierID, periodID])
//@@unique([offerID, periodID, carrierID]) // This would fix it, but it is not necessary as for uniquess the order of columns does not matter
@@index([offerID], map: "idZak")
@@index([offerID, periodID, carrierID], map: "nabzak_zaknos")
@@index([carrierID], map: "ncis")
}
model CarrierInPeriod {
offerID Int @map("idZak") @db.UnsignedSmallInt
periodID Int @map("idObdobi") @db.UnsignedSmallInt
carrierID Int @map("ncis")
nabzak nabzak?
@@id([offerID, periodID, carrierID])
@@index([offerID, periodID], map: "IDZak & IDObdobi")
@@index([offerID, carrierID], map: "IDZak & ncis")
}
Environment & setup
- OS: Windows
- Database: MySQL
- Node.js version: v16.13.2
Prisma Version
prisma : 4.1.1
@prisma/client : 4.1.1
Current platform : windows
Query Engine (Node-API) : libquery-engine 8d8414deb360336e4698a65aa45a1fbaf1ce13d8 (at node_modules\@prisma\engines\query_engine-windows.dll.node)
Migration Engine : migration-engine-cli 8d8414deb360336e4698a65aa45a1fbaf1ce13d8 (at node_modules\@prisma\engines\migration-engine-windows.exe)
Introspection Engine : introspection-core 8d8414deb360336e4698a65aa45a1fbaf1ce13d8 (at node_modules\@prisma\engines\introspection-engine-windows.exe)
Format Binary : prisma-fmt 8d8414deb360336e4698a65aa45a1fbaf1ce13d8 (at node_modules\@prisma\engines\prisma-fmt-windows.exe)
Default Engines Hash : 8d8414deb360336e4698a65aa45a1fbaf1ce13d8
Studio : 0.469.0
Preview Features : interactiveTransactions
Issue Analytics
- State:
- Created a year ago
- Comments:9 (9 by maintainers)
Top Results From Across the Web
error parsing attribute @relation: a one-to-one relation must ...
Error code: P1012 error: Error parsing attribute "@relation": A one-to-one relation must use unique fields on the defining side. Either add an `@unique`...
Read more >Prisma schema API (Reference)
Sets whether referential integrity is enforced by foreign keys in the database or emulated in the Prisma Client. In preview in versions 3.1.1...
Read more >Web service error codes (Microsoft Dataverse) - Power Apps
Message: Given linked attribute is alreadly linked to other attribute. 0x80094002 ... Message: Crm expression body parsing error occurred.
Read more >RFC 3501: INTERNET MESSAGE ACCESS PROTOCOL
Any client command with a protocol syntax error, including (but not limited ... Message Sequence Number Message Attribute A relative position from 1...
Read more >Creating an index > Data types - Manticore Search Manual
To do that efficiently, Manticore enables not only full-text fields, but additional attributes to each document. It's then possible to use them to...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@janpio @tomhoule I have used the expression
SET foreign_key_checks = 0
to disable foreign key checks off.@janpio Yes but, I am not sure if it is MySQL only error