Unique constraint failed on the constraint: `dbo.User`

Hello, I'm new to prisma and am learning how to use the createMany method. I keep receiving the error stated in the title but don't understand why. When I use the create method and run the script it successfully creates a new user.
No description
No description
No description
2 Replies
devrev1
devrev1OP2w ago
I believe I figured it out. I am using SQL Server and I think that it counts NULL values as unique. So when I was creating each user it was assigning them both NULL values which violated the uniqueness constraint on userPreferenceId. The tutorial I was watching was using Postgres, that is the only other difference.
devrev1
devrev1OP2w ago
What I ended up doing was modifying my schema so that the UserPreference model has the foreign key field. It was originally on the User model so that I could use include: { userPreferences: true } when using create(). With this schema change I was able to use createMany as expected:
No description

Did you find this page helpful?