P
Prisma6mo ago
Tarna

Unique Constraints Failed

When adding a record with prisma studio, I am getting the error "Unique constraint failed on the constraint: `Server_secret_key`". I don't have any field named "Server_secret_key" so I don't know why its saying that.
6 Replies
Nurul
Nurul6mo ago
Can you try generating your Prisma Client again and checking? npx prisma generate
Tarna
TarnaOP6mo ago
same thing happens. the only 2 values that I have on that model that are marked as unique are token and name.
Nurul
Nurul6mo ago
Can you shate your model in which you are getting this error? I'll try to reproduce.
Tarna
TarnaOP6mo ago
model Server {
id String @id @default(cuid()) @map("_id")
token String @unique
name String @unique
ip String
port Int
motd String @default("A Minecraft Server")

icon String @default("OAK_SIGN")
categories String[] @default([])
suspended Boolean @default(false)
joins Int @default(0)

owner Player? @relation(fields: [ownerId], references: [id])
ownerId String?

createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
model Server {
id String @id @default(cuid()) @map("_id")
token String @unique
name String @unique
ip String
port Int
motd String @default("A Minecraft Server")

icon String @default("OAK_SIGN")
categories String[] @default([])
suspended Boolean @default(false)
joins Int @default(0)

owner Player? @relation(fields: [ownerId], references: [id])
ownerId String?

createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
the model looks like this. it is using mongodb as the provider. I still haven't been able to figure out this issue I legit removed all @unique and it still is saying unique constraints failed
Nurul
Nurul6mo ago
What happens if you do npx prisma db pull? Do you get a field named secret_key in your Server model?
Tarna
TarnaOP6mo ago
im using mongo so it doesnt seem to support it. but I did it with --force and it shows a field named secret with the type Json? tho I don't see that field when I view the database through mongo cloud well no currently documents for server currently exist so not sure where it got that from
Want results from more Discord servers?
Add your server