You can manually specify id values and not have any default like this:

id        String   @id

In such a case, you would have to manually specify the id field when creating a new object. If you'd like to use some arbitrary database function to generate default values for the field, you can also take a look at dbgenerated().

Answer from Tasin Ishmam on Stack Overflow
🌐
Prisma
prisma.io › home › crud › crud › crud › crud
CRUD (Reference) | Prisma Documentation
const user = await prisma.user.create({ ... Postgres if you want a managed database to try these examples against quickly · The id is auto-generated....
🌐
Prisma
prisma.io › home › working with compound ids and unique constraints › working with compound ids and unique constraints › working with compound ids and unique constraints › working with compound ids and unique constraints
Working with compound IDs and unique constraints (Concepts) | Prisma Documentation
You can also create a named compound ID or compound unique constraint by using the @@id or @@unique attributes' name field. For example: model Like { postId Int userId Int User User @relation(fields: [userId], references: [id]) Post Post ...
Discussions

How to store custom ID?
Hi I'm pretty new to prisma, I ... to store ID as custom prefix such as SK00XXX something like this So whenever I add user it should store as SK00001 and incrementing value ... Beta Was this translation helpful? Give feedback. ... Thank you for raising this question. Currently, Prisma does not have support for creating custom IDs ... More on github.com
🌐 github.com
3
4
Custom ID Generator as an alternative to middleware
Problem Prisma provides a way to autogenerate ids with @default however only few functions are available: cuid uuid and autoincrement. When using custom IDs, you'll have to manually provide the ID to the create function. This results in ... More on github.com
🌐 github.com
3
March 3, 2022
Using prisma how to get the newly created records id(pk)?
After creating a new record using Prisma ORM how do I get the ID of newly created record to do some other operation using that ID? For example in Laravel Eloquent I could create a product using More on stackoverflow.com
🌐 stackoverflow.com
Prisma client: Can't provide Id for reference
I tried in both directions: User ... Employee creates user. With the commented code, I get a similar message Argument employeeId for data.employeeId is missing.. I guess I can't make this work because they both reference each other (even if they are optional)? If so, what would make the most sense from a security/db perspective? I saw a suggestion about using select to return the id but unless I'm not using it the right way, it doesn't work. Using Nexus-Prisma in the background, ... More on github.com
🌐 github.com
2
1
May 4, 2022
🌐
GitHub
github.com › prisma › prisma › discussions › 21351
Id not generated on `prisma.[model].create` if schema using `@default(dbgenerated("gen_random_uuid()"))` · prisma/prisma · Discussion #21351
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. To Reproduce Im using prisma client 4.16.1 and my postgres db is using postgres 14.6 · Create 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.
Author   prisma
🌐
Prisma
prisma.io › home › models › models › models › models
Models | Prisma Documentation
MongoDB does not support @@id MongoDB does not support composite IDs, which means you cannot identify a model with a @@id block. You can define default values for scalar fields using the @default attribute: model Post { id Int @id @default(autoincrement()) createdAt DateTime @default(now()) title String published Boolean @default(false) data Json @default("{ \"hello\": \"world\" }") }
🌐
GitHub
github.com › prisma › prisma › discussions › 20865
How to store custom ID? · prisma/prisma · Discussion #20865
CREATE OR REPLACE FUNCTION generate_custom_id(prefix text, start_value smallint, padding_length smallint) RETURNS text AS $$ DECLARE new_value smallint; formatted_id text; BEGIN SELECT max(CAST(SUBSTRING(id, length(prefix) + 1) AS smallint)) INTO new_value FROM "Product"; -- Change "Product" to the actual table name IF new_value IS NULL THEN new_value := start_value; ELSE new_value := new_value + 1; END IF; formatted_id := prefix || lpad(new_value::text, padding_length, '0'); RETURN formatted_id; END; $$ LANGUAGE PLPGSQL VOLATILE; Run npx prisma migrate dev to finish creating the migration.
Author   prisma
🌐
Prisma
prisma.io › home › schema api › schema api › schema api
Prisma Schema API | Prisma Documentation
Create a sequence of integers in the underlying database and assign the incremented values to the values of the created records based on the sequence. model User { id Int @id @default(sequence(maxValue: 4294967295)) name String } Generate a ...
Find elsewhere
🌐
GitHub
github.com › prisma › prisma › issues › 12125
Custom ID Generator as an alternative to middleware · Issue #12125 · prisma/prisma
March 3, 2022 - A way to achieve this is to allow @default(customIdGenerator()) in the schema file and then set globally an ID generator on the Prisma object, maybe something like this: Prisma.setIdGenerator((data) => { // this will return return ...
Author   prisma
🌐
GitHub
github.com › prisma › prisma › discussions › 13121
Prisma client: Can't provide Id for reference · prisma/prisma · Discussion #13121
May 4, 2022 - The principle: A user can create multiple employees and then give them access by adding them as a user. An employee can have a user account. A user can be an employee. Only one user account per employee. Also, by putting the password in a different table I hope to mitigate some accidental leaks where the password might be sent to the client, etc. [I still need to encrypt email and phone number in the db, but Prisma doesn't support it I believe] ... model User { id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid username String @unique password_hash Bytes employee Employee?
Author   prisma
🌐
Reddit
reddit.com › r/supabase › setting the default value for an id column through prisma
r/Supabase on Reddit: Setting the default value for an id column through Prisma
February 9, 2023 -

Below is an example model where I set the id to a default value as uuid() so that I don't need to pass an id when inserting a row. However, although Supabase has uuid type which can be set to uuid_generate_v4() as default, since Prisma does not have such a type Supabase does not generate a uuid_generate_v4() for a string type.

Is there a solution to this problem? Or should I simply generate an id and pass it when inserting a row?

model Posts {
  id                  String      @id @unique @default(uuid())
  createdAt           DateTime    @default(now())
}
🌐
Stack Overflow
stackoverflow.com › questions › 77693876 › prisma-create-connect-vs-id-in-data-object
Prisma create -> connect vs id in data object - Stack Overflow
E.g.: // Approach 1: using the data object directly prisma.item.create({ data: { id: "abc", value: "dummy", groupId: "xyz" } }) // Approach 2: using the connect parameter prisma.item.create({ data: { id: "abc", value: "dummy", group: { connect: ...
🌐
Goprisma
goprisma.org › docs › walkthrough › create
Create records – Prisma Client Go
October 22, 2024 - The examples use the following prisma schema: model Post { id String @id @default(cuid()) createdAt DateTime @default(now()) updatedAt DateTime @updatedAt published Boolean title String content String?
🌐
Prisma
prisma.io › home › prisma client api › prisma client api › prisma client api
Prisma Client API | Prisma Documentation
Conversely, if connect is applied before set, the set operation will override the connect action by clearing all connected records and replacing them with its own specified state. const user = await prisma.profile.create({ data: { bio: "Hello World", user: { connect: { email: "alice@prisma.io" }, }, }, }); const user = await prisma.profile.create({ data: { bio: "Hello World", user: { connect: { id: 42 }, // sets userId of Profile record }, }, });
🌐
Prisma
prisma.io › home › relations › relations › relations › relations
Relations | Prisma Documentation
model User { id Int @id @default(autoincrement()) posts Post[] } model Post { id Int @id @default(autoincrement()) author User @relation(fields: [authorId], references: [id]) authorId Int // Foreign key connecting Post to User title String } At a Prisma ORM level, the User / Post relation consists of: Relation fields (author and posts): Define connections at Prisma ORM level, do not exist in the database · Relation scalar field (authorId): The foreign key that exists in the database · In SQL, you use a foreign key to create a relation between two tables:
🌐
GitHub
github.com › prisma › prisma › issues › 7093
When using a `connect` or `create` block in a `create()` or `update()`, other scalar relation fields cannot be used directly · Issue #7093 · prisma/prisma
May 14, 2021 - prisma.mainItem.create({ data: { related_item_one: { connect: { id: 123 } }, related_item_two: { create: {} }, } })
Author   prisma
🌐
Basedash
basedash.com › home › blog › how to generate uuids in prisma
How to generate UUIDs in Prisma | Basedash
January 31, 2025 - When you create a new user, Prisma will automatically populate the id field with a UUID.
🌐
DEV Community
dev.to › prageethsilva › human-readable-ids-in-prismajs-with-one-line-of-code-528l
Human-Readable IDs in PrismaJS with a few lines of code - DEV Community
April 5, 2025 - import { PrismaClient } from "@prisma/client"; import { extendPrismaClient } from "prisma-prefixed-ids"; const prisma = new PrismaClient(); const db = extendPrismaClient(prisma, { prefixes: { User: "usr", Organization: "org", }, }); ... const user = await db.user.create({ data: { name: "Alice", email: "alice@example.com" } }); console.log(user.id); // "usr_xxxxxxxx" No need to manually set IDs—they’re generated automatically with the correct prefix.