Schema Definition & Models in Prisma

From the Prisma ORM cheat sheet · Prisma Schema & Models · verified Jul 2026

Schema Definition & Models

Define your database schema using Prisma Schema Language with models, fields, and attributes

typescript
// schema.prisma
generator client {
  provider = "prisma-client-js"
}

datasource db {
  provider = "postgresql"
  url      = env("DATABASE_URL")
}

model User {
  id        Int      @id @default(autoincrement())
  email     String   @unique
  name      String?
  posts     Post[]
  createdAt DateTime @default(now())
  updatedAt DateTime @updatedAt

  @@map("users")
}

model Post {
  id       Int    @id @default(autoincrement())
  title    String
  content  String?
  authorId Int
  author   User   @relation(fields: [authorId], references: [id])

  @@map("posts")
}

// BASH_BLOCK:
# Generate Prisma Client after schema changes
npx prisma generate

# Format schema file
npx prisma format

# Validate schema
npx prisma validate

# Open Prisma Studio to view data
npx prisma studio
💡 Prisma schema is the single source of truth for your database
⚡ Run npx prisma generate after schema changes
📌 Use npx prisma format to auto-format schema
✅ VSCode extension provides syntax highlighting

Continue with Prisma ORM

Save the full cheat sheet or work through every related task.

More Prisma tasks

Back to the full Prisma ORM cheat sheet