UPD: problem solved. I completely forgot about the...
# orm-help
m
UPD: problem solved. I completely forgot about the fact that from
User
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:
Copy code
model User {
  userId                Int              @id @default(autoincrement())

  creatorFor Task? @relation(name: "creator")
  illustratorFor Task? @relation(name: "illustrator")
  motionerFor Task? @relation(name: "motioner")
}
Copy code
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:
Copy code
-- 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 migrations
So as it turned out, even manually changing the migrations does not help. Since the prism itself does not allow making an insert, which, as it seems to it, violates the index that it created
r
Hey @Mykyta Machekhin 👋 Is your issue about this solved?
m
@Ryan Yes. Just decided it was better not to delete the message
🙌 1