Schema Definition & Models in Prisma

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

Schema Definition & Models

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

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

datasource db {
  provider = "postgresql"
}

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")
}

// prisma.config.ts (project root): the connection URL lives here in Prisma 7
import 'dotenv/config'
import { defineConfig, env } from 'prisma/config'

export default defineConfig({
  schema: 'prisma/schema.prisma',
  migrations: { path: 'prisma/migrations' },
  datasource: { url: env('DATABASE_URL') },
})
bash
# 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
💡 The Prisma schema is the single source of truth for your data model; the connection URL lives in prisma.config.ts
⚡ Run npx prisma generate after schema changes (migrate dev no longer runs it in Prisma 7)
📌 The prisma-client generator requires an output path; import PrismaClient from that folder
✅ Use npx prisma format and npx prisma validate to check the schema

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