question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error parsing attribute "@relation" when unique/id index is in different order

See original GitHub issue

Bug 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

  1. Create a model from the template below
  2. 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:open
  • Created a year ago
  • Comments:9 (9 by maintainers)

github_iconTop GitHub Comments

2reactions
Akxecommented, Oct 5, 2022

@janpio @tomhoule I have used the expression SET foreign_key_checks = 0 to disable foreign key checks off.

1reaction
Akxecommented, Aug 4, 2022

So the bug should be that uniqueness of fields are guaranteed by @@unique and @@id in any order of the combined fields, not just by the one in use in fields. Correct @Akxe?

@janpio Yes but, I am not sure if it is MySQL only error

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found