#Generating cuid ids in postgres doesnt work

2 messages · Page 1 of 1 (latest)

signal galleon
#

Hi, im trying to generate a cuid in PostgresSql with prisma by default.

This is my schema:

model Room {
  id String @id @default(cuid())
}

This is my Code (NextJS server action):

export const createRoom = async () => {
  await prisma.room.create({});
};

I get this Error:

Null constraint violation on the fields: (`id`)
    at async createRoom

This is the query which is executed

INSERT INTO "public"."Room" DEFAULT VALUES RETURNING "public"."Room"."id"

Do I need to create the cuid myself when i create a room?

low spade
#

Why do you need a table with no fields tho?
I think that if you add a name or description or whatever second field everything will work fine