As for BigInt, it showed better accuracy with ID w...
# orm-help
m
As for BigInt, it showed better accuracy with ID which I was storing before in database.
2
n
Hey @Edun omatseye and @MrDell 👋 thanks a lot for the helpful discussion here 😄 it would be great (if in the future) you could continue the conversation in a thread (like this one) to keep the main channel clear for new questions 🙂
🙌 1
m
Alright, I am kind of new to Slack so sorry for the mess.
m
I'm trying to learn here too - so while I think I see what's going on - take my advice as that from a newb. @MrDell It seems like you won't be able to use your interaction.user.id at all for the PK, since Prisma can't guarantee uniqueness. Adding the uniqueness constraint I think is unhelpful, because @id is putting the primary key constraint on the record anyway - so uniqueness is already required. I think your idea about adding the interaction.user.id as a non-id field is the right one. But if it is supposed to be unique, it seems like you'll need some backend logic to make certain that the userId isn't already associated with another record when you perform your creation.
m
I see and on the note, the id, which is being sent by API is totally unique and it will not cause any crash or being associated with other entity.
I'II try to implement it as non-PK field. Thanks for the advice!
Hi, I've also tried with adding User ID in different field with unique tag on it but the error still persist.
Copy code
model Player {
  id            String  @id @default(cuid())
  discord_id    BigInt  @unique
  createdAt    DateTime?   @default(now())
  region       String
  country      String
  timezone     String
  Tournaments Tournament[]
}
with the error of
Copy code
Invalid `prisma.player.create()` invocation:


  Unique constraint failed on the fields: (`discord_id`)
m
That's what I'm trying to say - you can't put the unique tag on it, because although YOU know you'll be passing a unique value, Prisma doesn't trust you. That's why you had to pull it off of @id - because Prisma can't ensure its uniqueness. That's why I was recommending you implement BE logic to ensure uniqueness - it can't be done on the DB level here. Try just removing the unique constraint - it should work then.
m
Oh, now i got it. I was thinking it wrong whole the time.
My bad.