Mykyta Machekhin
01/31/2021, 10:14 PMUser
this relation type is many to one. Therefore, there should be lists instead single values. Without this, prisma perceives this relation as one to one. What explains creating a unique index
Hello. Seems to have found a bug in the prisma, but I’m not sure about that yet. Therefore, before creating an issue, I want to discuss here. The problem is that the prisma for some reason creates a unique index where it shouldn’t. As a result, I cannot insert duplicate values where they might be
How to reproduce:
In my case I have 2 models, which have three relations:
model User {
userId Int @id @default(autoincrement())
creatorFor Task? @relation(name: "creator")
illustratorFor Task? @relation(name: "illustrator")
motionerFor Task? @relation(name: "motioner")
}
model Task {
taskId Int @id @default(autoincrement())
name String
creator User @relation(fields: [creatorId], references: [userId], name: "creator")
illustrator User? @relation(fields: [illustratorId], references: [userId], name: "illustrator")
motioner User? @relation(fields: [motionerId], references: [userId], name: "motioner")
creatorId Int
illustratorId Int?
motionerId Int?
}
When 2 models are linked by more than 1 relations, the prisma requires you to create names for them in the parent entity, therefore the user has 3 last lines
In this example, I do not need the creator, illustrator, and motion designer to be unique in the task model. However, here’s what I see in the migration:
-- CreateIndex
CREATE UNIQUE INDEX "Task_creatorId_unique" ON "Task"("creatorId");
-- CreateIndex
CREATE UNIQUE INDEX "Task_illustratorId_unique" ON "Task"("illustratorId");
-- CreateIndex
CREATE UNIQUE INDEX "Task_motionerId_unique" ON "Task"("motionerId");
I can’t explain it, and I don’t know what to do with it other than manual editing of migrationsMykyta Machekhin
01/31/2021, 10:48 PMRyan
02/01/2021, 7:48 AMMykyta Machekhin
02/01/2021, 7:51 AM