Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Prisma · Const

@default

@default defines the value Prisma or the database uses when a scalar field is omitted during creation. It accepts literals, supported functions, and database-generated expressions.

How it works

Place @default on a scalar field to supply its value when a create operation omits that field. The value can be a literal, a Prisma-provided function such as now(), cuid(), or uuid(), or a database-generated expression; relation fields themselves cannot receive defaults.

Syntax

@default(_ value: Expression, map: String?)

Parameters

NameTypeDescription
valueExpressionDefault expression, such as a literal, function, or database-generated value.
mapString?Optional mapped database default name; SQL Server only.

Returns

A default value for the annotated scalar field.

Key points

  • The attribute belongs on scalar model fields and fills in omitted values during record creation.
  • Some defaults are stored as database-level DEFAULT expressions rather than generated by application code.
  • Functions such as now(), cuid(), and uuid() can provide generated defaults through Prisma ORM.
  • Prisma's query engine supplies cuid() and uuid() across connectors.
  • Scalar-list defaults are available when the database natively supports scalar lists.

Common mistakes

  • Do not attach @default directly to a relation field. Put the default on a scalar field that backs the relation instead.
  • Represent JSON defaults as quoted strings, escaping internal double quotes when defining an object.
  • A default on a relation's backing scalar can cause the relation to be populated automatically.

Example: Scalar field defaults

model User {
  id        Int      @id @default(autoincrement())
  createdAt DateTime @default(now())
  active    Boolean  @default(true)
}

This model assigns an automatically generated integer ID, the creation timestamp, and an initial Boolean value when records are created.

When to use it

Generated primary keys

Assign generated identifiers without passing an ID from application code.

Automatic timestamps

Set creation timestamps automatically when records are inserted.

Initial field state

Initialize flags, counters, JSON values, or scalar lists with consistent defaults.

Interview questions

QWhat does @default do?

@default supplies a value when a scalar field is not provided during creation. It may represent a database DEFAULT or use a Prisma ORM-level function, depending on the expression.

Follow-up: How would you model a default on a relation? Use the scalar field listed in the relation's fields argument; relation fields themselves cannot have defaults.

QWhich kinds of values can @default contain?

Use literals such as false or quoted JSON, and functions such as now(), cuid(), uuid(), and autoincrement() where supported. Prisma-provided cuid() and uuid() are generated by Prisma Client's query engine for all connectors.

Follow-up: What is required for a JSON object default? Quote the entire JSON value and escape each internal double quote with a backslash.

QDoes Prisma always generate the default value?

For relational databases, a default can become a database DEFAULT value, while some functions are evaluated by Prisma ORM. This distinction affects where the value is generated.

Follow-up: How are unsupported database defaults represented after introspection? Prisma uses dbgenerated() for defaults that cannot yet be expressed in the schema.

  • @id
  • @relation
  • autoincrement()
  • cuid()
  • uuid()
  • now()
  • dbgenerated()

Source: Prisma Schema API (Prisma ORM v6). Checked 2026-10-16.