Next.js Discord

Discord Forum

Invalid `prisma.user.create()` invocation:Unique constraint failed on the fields: (`email`)

Unanswered
Gray-crowned Yellowthroat posted this in #help-forum
Open in Discord
Gray-crowned YellowthroatOP
Please someone help me with this error

2 Replies

Cape lion
Usually don't send pictures of your code the second image is unreadable.Please give the code in a code block,
without seeing your model definition, it would be harder for anyone to find solution. But to take a guess, it is related to email field in your User model which you have declared as unique.

potention reasons:
1. You are trying to create a new user with an email that already exists in the database but email being a unique field makes prisma hard to decide that user exists or not.
(SOL: replace id with email in your prisma.user.findUnique if email field is set to unique in your db)
2. You are trying to assign id yourself instead of prisma doing it automatically for you.
(SOL: remove the id field in prisma.user.create())