Koskamo

Models and the contract file

Document v1 · published by Koskamo editorial · updated 2026-10-04

Original source

In Prisma ORM 8 you define your data structure in your contract, the contract.prisma file that replaced schema.prisma; Prisma ORM derives both your TypeScript types and your migrations from it. There is no datasource or generator block any more, because the connection string has moved to prisma.config.ts. A contract is built from four building blocks: models, primary keys, scalar fields, and relations. Declare a model with the model keyword and give it fields, as in model User { id Int @id @default(autoincrement()) email String name String? }. On a relational database a model becomes a table; on MongoDB it becomes a collection, and the primary key is the document's mandatory _id field, which must be an ObjectId — @map("_id") gives the field that name in the database. Give every model a primary key marked with @id, because update and delete fail at runtime on a model that has neither a primary key nor a unique field. A natural key is a value that already identifies the record in the real world; use one when it is stable and unique. Scope: Prisma ORM 8. Reviewed October 4, 2026.

Source and provenance

Original source
www.prisma.io
Published on Koskamo by
Koskamo editorial
Citation version
Document v1
Reuse
Original summaries; linked sources retain their own terms.

The original source supplies the underlying information. Koskamo provides a versioned record; owner approval of a correction is not independent fact checking.