I’ve tried virtually everything to auto generate U...
# orm-help
i
I’ve tried virtually everything to auto generate UUIDs and nothing has worked. In Postico, I’ve looked at the structure for the
id
column and the expression for uuid is not there. Any advice/direction would be appreciated
I noticed this thread: https://prisma.slack.com/archives/CA491RJH0/p1603875562428300?thread_ts=1603874759.428100&cid=CA491RJH0 I think this is a design flaw of Prisma. IMO, Prisma should take advantaged of Postgres’s native ability to generate UUIDs. Not everything can be done at runtime and the actual Postgres schema should not be limited to runtime
n
Hey Clayton 👋 thanks for bringing this up. When using
@default(uuid())
in your Prisma schema, the UUID values are indeed generated by the Prisma query engine and not the DB. It's not yet possible to map this behaviour from Postgres to the Prisma schema in another way.
I think this is a design flaw of Prisma. IMO, Prisma should take advantaged of Postgres’s native ability to generate UUIDs.
I think we actually agree with you here and want to fix this. Do you mind creating a GitHub issue so this can be tracked properly? 🙂
Also, just for context, this is documented here.
a
Hello @iamclaytonray, If I understand correctly, you want the database to generate the UUIDs for a column default. If this is indeed your intention, this should be possible now starting with 2.16.0 using the
nativeTypes
feature (in Preview) and
dbgenerated(String)
. Example:
Copy code
model User {
  id   String  @id @db.Uuid @default(dbgenerated("gen_random_uuid()"))
  name String?
}
Release notes: https://github.com/prisma/prisma/releases/tag/2.16.0
i
Ahh, that makes sense. I’ll try using the native types this week and if that doesn’t do what I’m expecting, I’ll create an issue to track. Thanks everyone!
prisma rainbow 2