P
Prisma8mo ago
Wiznet

Prisma format fails with disambigious relations

Hey all, not sure if this is my own error here. But I've got the below schema that fails to get formatted by prisma format. I've got quite a few relations setup on a user model. However, running prisma format fails when trying to insert the relations onto the user model. I've added both the errpr and my source schema below. It seems like prisma format fails to name the ambigious relations on the user model.
model ListingApplication {
id String @id @default(cuid())
description String?
listingId String
brandId String
userId String
applicationStatus ApplicationStatus

createdOn DateTime
createdBy String
updatedOn DateTime
updatedBy String
status String

user User @relation("applyingUser", fields: [ userId], references: [id])
creatingUser User @relation("creatingUser", fields: [ createdBy], references: [id])
updatingUser User @relation("updatingUser", fields: [ updatedBy], references: [id])
listing Listing @relation(fields: [listingId], references: [id])
brand Brand @relation(fields: [brandId], references: [id])
}
model ListingApplication {
id String @id @default(cuid())
description String?
listingId String
brandId String
userId String
applicationStatus ApplicationStatus

createdOn DateTime
createdBy String
updatedOn DateTime
updatedBy String
status String

user User @relation("applyingUser", fields: [ userId], references: [id])
creatingUser User @relation("creatingUser", fields: [ createdBy], references: [id])
updatingUser User @relation("updatingUser", fields: [ updatedBy], references: [id])
listing Listing @relation(fields: [listingId], references: [id])
brand Brand @relation(fields: [brandId], references: [id])
}
Error: Prisma schema validation - (validate wasm)
Error code: P1012
error: Field "ListingApplication" is already defined on model "User".
--> schema.prisma:64
|
63 | ListingApplication ListingApplication[]
64 | ListingApplication ListingApplication[]
|
error: Field "ListingApplication" is already defined on model "User".
--> schema.prisma:65
|
64 | ListingApplication ListingApplication[]
65 | ListingApplication ListingApplication[]
|

Validation Error Count: 2
[Context: validate]
Error: Prisma schema validation - (validate wasm)
Error code: P1012
error: Field "ListingApplication" is already defined on model "User".
--> schema.prisma:64
|
63 | ListingApplication ListingApplication[]
64 | ListingApplication ListingApplication[]
|
error: Field "ListingApplication" is already defined on model "User".
--> schema.prisma:65
|
64 | ListingApplication ListingApplication[]
65 | ListingApplication ListingApplication[]
|

Validation Error Count: 2
[Context: validate]
3 Replies
Wiznet
WiznetOP8mo ago
yeah i had to manually add my disambiguous relations
Wiznet
WiznetOP8mo ago
seems this must be a bug. Found this issue filed: https://github.com/prisma/prisma/issues/24132
GitHub
Disambiguating relations incorrectly auto formatting · Issue #2413...
Bug description When creating a model that has disambiguous relations with a relational db the formatter prisma format will generate the @relation(fields: [authorId], references: [id]) automaticall...
Wiznet
WiznetOP8mo ago
bumping this
Want results from more Discord servers?
Add your server