Getting an error upgrading to 3.0 error: Error pa...
# orm-help
c
Getting an error upgrading to 3.0 error: Error parsing attribute "@relation": When any of the records in models
HRDepartment
,
JobTitle
,
JobType
,
LegalDepartment
,
OfficeLocation
,
Person
,
Photo
are updated or deleted, the referential actions on the relations cascade to model
PersonRelationship
through multiple paths. Please break one of these paths by setting the
onUpdate
and
onDelete
to
NoAction
. (Implicit default `onUpdate`:
Cascade
) Read more at https://pris.ly/d/cyclic-referential-actions --> schema.prisma:602 | 601 | ValidToDate DateTime 602 | RelatedPerson Person @relation(name: "RelatedPerson", fields: [RelatedPersonID], references: [PKPersonID]) 603 | SupportedPerson Person @relation(name: "SupportedPerson", fields: [RelatedPersonID], references: [PKPersonID])
Copy code
model PersonRelationship {
  PersonRelationshipID Int              @id @default(autoincrement())
  PKPersonID           Int
  RelationshipTypeID   Int
  RelatedPersonID      Int
  Description          String?          @db.VarChar(Max)
  Active               Boolean
  ActiveFromDate       DateTime         @db.Date
  ModifiedDate         DateTime         @db.DateTime
  ModifiedBy           String           @db.VarChar(30)
  ValidFromDate        DateTime
  ValidToDate          DateTime
  RelatedPerson        Person          @relation(name: "RelatedPerson", fields: [RelatedPersonID], references: [PKPersonID], onDelete: NoAction, onUpdate: NoAction)
  SupportedPerson      Person          @relation(name: "SupportedPerson", fields: [RelatedPersonID], references: [PKPersonID], onDelete: NoAction, onUpdate: NoAction)
  Person               Person          @relation(name: "PrimaryPerson", fields: [PKPersonID], references: [PKPersonID], onDelete: NoAction, onUpdate: NoAction)

  RelationshipType     RelationshipType @relation(fields: [RelationshipTypeID], references: [RelationshipTypeID])
  
  @@unique([PKPersonID, RelatedPersonID, RelationshipTypeID], name: "nclunq_PersonRelationship_PKPersonID_RelatedPersonID_RelationshipTypeID")
}
t
Hi Chip! If all your relations have onUpdate and onDelete set to
noAction
and you see this message, it's probably a bug. Would you be comfortable sharing your whole schema?
j
yep we really need the whole datamodel to solve this
it would be extremely useful to get, so we can debug this ASAP if we have a bug, could you send it to schemas@prisma.io
c
sent via email
j
reading the schema now
did you ever do a
prisma db pull
with the version 3 before using the client?
we have breaking changes in prisma 3, and some of them might also lead to data loss if not careful
but I cannot detect the cycles from here, there are certain things you can solve by running
prisma db pull
regarding constraint names
please see the upgrade docs in https://www.prisma.io/docs/guides/upgrade-guides/upgrading-versions/upgrading-to-prisma-3, especially the referential actions and named constraints ones
and if you find a cycle or multiple cascading paths when there should be none, please file an issue and it will get prioritized with the highest priority
c
λ npx prisma db pull Environment variables loaded from ..\.env Prisma schema loaded from schema.prisma Datasource "db" - SQL Server Introspecting based on datasource defined in schema.prisma … Error: P1012 Introspection failed as your current Prisma schema file is invalid Please fix your current schema manually, use prisma validate to confirm it is valid and then run this command again. Or run this command with the --force flag to ignore your current schema and overwrite it. All local modifications will be lost. C:\Sites\prismaAPI\AM-API-MDD\prisma (master -> origin) λ npx prisma validate Environment variables loaded from ..\.env Prisma schema loaded from schema.prisma Error: Schema parsing error: Error parsing attribute "@relation": Given constraint name is already in use in the data model. --> schema.prisma:1 | | 1 | | ^ Unexpected token. | error: Error parsing attribute "@relation": Given constraint name is already in use in the data model. --> schema.prisma:1 | | 1 | | ^ Unexpected token. | Validation Error Count: 2
λ npx prisma db pull --force Environment variables loaded from ..\.env Prisma schema loaded from schema.prisma Datasource "db" - SQL Server Introspecting based on datasource defined in schema.prisma … ✔️ Introspected 60 models and wrote them into schema.prisma in 1.53s * WARNING * The following models were commented out as they do not have a valid unique identifier or id. This is currently not supported by the Prisma Client. - "Address_History" - "Email_History" - "Email_OLD_History" - "JobTitle_History" - "License_BKUP_04102019" - "License_History" - "License_TEST" - "Person_History" - "PersonPersonType_History" - "PersonRelationship_BKUP_04092019" - "PersonRelationship_History" - "Phone_History" - "Phone_OLD_History" - "Photo_History" - "TemplateMetadata_BKUP_20210422" - "TemplateMetadata_BKUP_20210503" - "TemplateMetadata_BKUP_20210518" Run prisma generate to generate Prisma Client. C:\Sites\prismaAPI\AM-API-MDD\prisma (master -> origin) λ npx prisma generate Environment variables loaded from ..\.env Prisma schema loaded from schema.prisma Error: binaryTargets.flatMap is not a function
I had to update schema.prisma manually to add the relationships that db pull removed. now getting the error: λ npx prisma generate Environment variables loaded from ..\.env Prisma schema loaded from schema.prisma thread '<unnamed>' panicked at 'Every RelationInfo should have a complementary RelationInfo on the opposite relation field.', libs\datamodel\connectors\dml\src\datamodel.rs:165:14 note: run with
RUST_BACKTRACE=1
environment variable to display a backtrace Error: Unexpected token E in JSON at position 0
sending new schema via email
j
can you file an issue and we can then actually schedule that to the next sprint?
c
ERROR: Every RelationInfo should have a complementary RelationInfo on the opposite relation field #9238 https://github.com/prisma/prisma/issues/9238