Hi everyone! I have a scenario where I need to ge...
# orm-help
l
Hi everyone! I have a scenario where I need to generate an entity’s id default value on the MySQL db level, instead of doing it on the Prisma level with
uuid()
. Having this entity:
Copy code
model Tag {
	id String @id @default(dbgenerated("(uuid())")) @db.Char(36)
	name String 
	description String? @db.Text
	slug String
	isTopic Boolean @default(false)
	articles Article[] 
}
When trying to insert a row via Prisma Studio (or via a
prisma.tag.create
inside
seed.ts
), I get this error:
Copy code
Message: 
Invalid `prisma.tag.create()` invocation:


  Could not figure out an ID in create

Query: 
prisma.tag.create(
{
  data: {
    name: "science",
    description: "science description",
    slug: "science",
    isTopic: false,
    articles: {

    },
  },
  select: {
    id: true,
    name: true,
    description: true,
    slug: true,
    isTopic: true,
    articles: true,
  },
}
I guess Prisma doesn’t see any id and since it is a mandatory field, it throws this. Shouldn’t the
dbgenerated
attribute tell Prisma “hey, no need to provide the id upon create, the db will generate it!“?
a
maybe your
articles {}
should be
articles: { create: {} }
l
That entire construct is auto-generated by Prisma Studio so I guess it’s fine as is.
a
ohh prisma studio can create row too, i didnt know
no idea then
try manually seeding
heres how i create id
Copy code
id            String  @id @default(cuid())
not sure, i've seen
dbgenerated
yet