Replies: 1 comment 4 replies
-
Did |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Bug description
When using the
create
api in prisma on a model that has the id with a@default(dbgenerated("gen_random_uuid()"))
I get aNull constraint violation on the fields: (
id)
error as the id remains undefined. When previously using just the prisma@default(uuid())
this wasn't a problem but I need the uuid generation to also live in the actual postgres schema so needed to usedbgenerated("gen_random_uuid()")
.So it seems when defining the constraint this way the uuid is not generated when prisma create is invoked on a model. Maybe this is intentional which then apologies for the created issue I'd be interested in how I can call the prisma create api in this scenario without triggering a non null constraint (obviously I want Id to have a non null constraint). The uuid default gen is correctly added to the actual db schema and inserting a record directly using sql will correctly generate the uuid id.
How to reproduce
To Reproduce
Im using prisma client
4.16.1
and my postgres db is using postgres 14.6Create a schema with a Postgres db where a model uses the
@default(dbgenerated("gen_random_uuid()"))
for an id field that also has the@id
and@postgresql.Uuid
attribute.Use the
prisma.[modelname].create()
method expecting a record to be created with a uuid generated from the database. but instead receive an error described above.Expected behavior
I expected the create api to still work with
@default(dbgenerated("gen_random_uuid()"))
and correctly generate a uuid for the new record.Prisma information
prisma version:
4.16.1
postgres version:
14.6
simplified schema example
example call to prisma create api
Environment & setup
Prisma Version
Beta Was this translation helpful? Give feedback.
All reactions