P
Prisma3w ago
dotEXE

How to update Prisma @unique

Hello, So I started a new NextJS project. I did this:
model Post {
id String @id @default(cuid())
title String
slug String
content String
updatedAt DateTime @updatedAt
createdAt DateTime @default(now())
}
model Post {
id String @id @default(cuid())
title String
slug String
content String
updatedAt DateTime @updatedAt
createdAt DateTime @default(now())
}
Then I added to slug @unique But when I tried to do
const post = await prisma.post.findUnique({
where: {
slug
}
});
const post = await prisma.post.findUnique({
where: {
slug
}
});
It gave me an error : Invalid prisma.user.findUnique() invocation: How do I apply the new @unique? the npx prisma db push did not work
8 Replies
Prisma AI Help
Greetings, curious mind! I'm the Prisma AI Help Bot. Want to chat with a human team member (ETA: TBD)? Or skip the wait and get my best guess right now? The speed of automation awaits you.
begot
begot3w ago
did you generate after pushing?
dotEXE
dotEXEOP3w ago
npx prisma generate? yes i did
begot
begot3w ago
have you also tried restarting the ts server? also, if you're able, you should verify that the db has been updated to match your schema
dotEXE
dotEXEOP3w ago
I just removed the model, did push/generate then again added the model with the @unique But could it be the npm run dev that I had to reset maybe? How do I verify?
begot
begot3w ago
strange. might be worth restarting your ide use prisma studio for example
dotEXE
dotEXEOP3w ago
It was the npm run dev, I made sure Thanks for trying to help ❤️
begot
begot3w ago
yeah that makes sense. i misunderstood your question earlier. glad you got it working

Did you find this page helpful?