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

Prisma · Const

@updatedAt

@updatedAt automatically tracks when a record was last updated. Prisma Client manages the value for DateTime fields when the application does not provide one.

How it works

@updatedAt is a Prisma schema attribute for DateTime fields. Prisma Client supplies the current time when you omit a value and updates the field when a record changes, while an update with an empty clause leaves it unchanged.

Syntax

updatedAt DateTime @updatedAt

Key points

  • Use it to keep a model field representing the record's most recent update time.
  • Prisma Client supplies the value when a write does not provide one.
  • Its timestamp logic runs in Prisma ORM instead of the database engine.

Common mistakes

  • An update that changes nothing does not refresh the timestamp.
  • The timestamp is managed by Prisma ORM rather than generated by the database.
  • On Prisma versions before 4.4.0, combining this attribute with now() could produce different times when application and database time zones differ.

Example: Track the last update time

model Post {
  id        Int      @id @default(autoincrement())
  updatedAt DateTime @updatedAt
}

Define a DateTime field with @updatedAt; Prisma Client fills it automatically and refreshes it when the record is updated.

When to use it

Last-modified tracking

You need an audit field showing the latest modification time for each row.

Automatic write metadata

Your application should populate update timestamps without repeating timestamp logic in every write.

ORM-level timestamp management

You want Prisma-managed time values rather than relying on a database timestamp expression.

Interview questions

QWhat does @updatedAt do?

It automatically stores when a record was last updated. If the application does not provide a time, Prisma Client sets the field automatically.

Follow-up: Where is the behavior implemented? It is implemented in the Prisma ORM layer, not as a database-side operation.

QHow is @updatedAt declared?

The field must use the DateTime type, and the attribute is placed after that field declaration. A typical declaration is updatedAt DateTime @updatedAt.

Follow-up: Can it be attached to a String field? No; the documentation specifies compatibility with DateTime fields.

QWhat happens during an empty update?

A normal update causes Prisma to refresh the timestamp, but an empty update clause leaves the existing value unchanged. This means no-op updates do not necessarily advance the field.

Follow-up: How can database-generated timestamps differ from this value? Database functions such as now() run at the database level, while @updatedAt runs in Prisma ORM.

  • DateTime
  • now()
  • @default

Source: Schema API - Prisma Documentation. Checked 2026-10-16.