Create a single record
Insert one model instance when the application has collected the required field values.
Prisma · Function
create() inserts one new database record through a generated Prisma Client model delegate. Supply the record values under data; nested writes can create related records in the same operation.
Call the generated model delegate's create method with a data object containing the values for the new record. Prisma inserts the record and resolves the call with the created record; nested create values can add related records in the same operation.
prisma.<model>.create({ data: { ... } })| Name | Type | Description |
|---|---|---|
args | UserCreateArgs (model-specific) | Object containing the values for the new record, including optional nested relation writes and query options documented for the model delegate. |
data | UserCreateInput | UserUncheckedCreateInput | Values to insert for the selected model; required and optional fields are determined by the Prisma schema. |
A promise resolving to the newly created record, shaped by the selected model and any select/include options.
import { PrismaClient } from "@prisma/client";
const prisma = new PrismaClient();
const user = await prisma.user.create({
data: {
email: "alice@prisma.io",
name: "Alice",
},
});
console.log(user);Creates one User record and returns the created object.
Insert one model instance when the application has collected the required field values.
Create a parent and associated child records in one nested write.
Add related records while modifying an existing parent.
create() method do?create() inserts one new database record. It receives arguments such as data, and the returned promise resolves to the created record.
Follow-up: How can one operation create related records? Use a nested create inside the parent operation, which can add a related record or set of records.
create()?The required fields come from the Prisma schema, while generated fields such as an id can be assigned automatically. The create call therefore only needs to provide fields that the schema requires from the caller.
Follow-up: How would you create several related records? Use nested create or nested createMany; use nested createMany when its supported options, such as duplicate skipping, are needed.
create useful?A nested create can be used when creating a new parent or updating an existing parent. It adds related records as part of that parent write.
Follow-up: What limitation distinguishes nested createMany? Relations cannot be accessed in a createMany query, so it cannot create multiple users and multiple posts as one nested write.
createMany()update()includeselectconnect