Create a single record
Insert one application entity, such as a user, with its required and optional fields.
Prisma · Module
Prisma Client's create operation inserts a new database record and returns it. It supports scalar values in data and nested creation of related records.
The create operation inserts one record through a Prisma Client model delegate. Pass the values in data; Prisma returns the newly inserted record, including generated values and database defaults. A nested create can additionally insert related records while creating the parent.
prisma.<model>.create({ data: { ... } })| Name | Type | Description |
|---|---|---|
args | CreateArgs | Object containing the values for the new record and optional query arguments. |
The newly created database record.
create operation inserts a new record into the database.const user = await prisma.user.create({
data: {
email: "alice@prisma.io",
name: "Alice",
},
});Creates one User record and returns the inserted record.
Insert one application entity, such as a user, with its required and optional fields.
Insert a parent and its related records during one write.
Obtain generated identifiers and database defaults immediately after insertion.
create operation do?create inserts a new database record and returns the created record. The required input is provided through the data object, which can contain scalar fields and nested relation writes.
Follow-up: How can related records be inserted in the same operation? Use a nested create inside the parent record’s relation field.
Call prisma.user.create with a data object containing the new user's fields. Prisma returns the inserted user, including generated values such as an ID and database defaults.
Follow-up: What happens when a field is omitted? The operation can succeed when the schema or database supplies a generated value or default, provided all required input is otherwise present.
create?A nested create adds a related record or multiple related records while creating the parent. Prisma connects the nested records to the parent without requiring the caller to manually provide the relation's foreign key.
Follow-up: Why can the foreign key be omitted for nested posts? Prisma derives and fills it from the parent record created by the operation.
createManycreateManyAndReturnnested createdata