pull (Prisma CLI v7)
Pull the state from the database to the Prisma schema using introspection
The prisma db pull command connects to your database and adds Prisma models to your Prisma schema that reflect the current database schema.
prisma db pull [options]The datasource URL configuration is read from the Prisma config file (e.g., prisma.config.ts).
Prerequisites
Section titled “Prerequisites”Configure your database connection in prisma.config.ts:
generator client {
provider = "prisma-client"
output = "../generated/prisma"
}
datasource db {
provider = "sqlite"
}import { defineConfig, env } from "prisma/config";
export default defineConfig({
schema: "prisma/schema.prisma",
migrations: {
path: "prisma/migrations",
},
datasource: {
url: env("DATABASE_URL"),
},
});| Flag | Description |
|---|---|
-h, --help |
Display help message |
--force |
Ignore current Prisma schema file |
--print |
Print the introspected Prisma schema to stdout |
Options
Section titled “Options”| Option | Description |
|---|---|
--config |
Custom path to your Prisma config file |
--schema |
Custom path to your Prisma schema |
--url |
Override the datasource URL from the Prisma config file |
--composite-type-depth |
Depth for introspecting composite types (e.g., MongoDB Embedded Documents). Default -1 for infinite depth, 0 to disable |
--schemas |
Specify database schemas to introspect (overrides datasource block) |
--local-d1 |
Generate a Prisma schema from a local Cloudflare D1 database |
Examples
Section titled “Examples”Introspect the database
Section titled “Introspect the database”bunx prisma db pullpnpm prisma db pullyarn prisma db pullnpx prisma db pullOutput:
Introspecting based on datasource defined in schema.prisma …
✔ Introspected 2 models and wrote them into schema.prisma in 38ms
Run prisma generate to generate Prisma Client.Specify a schema path
Section titled “Specify a schema path”bunx prisma db pull --schema=./alternative/schema.prismapnpm prisma db pull --schema=./alternative/schema.prismayarn prisma db pull --schema=./alternative/schema.prismanpx prisma db pull --schema=./alternative/schema.prismaPrint to stdout instead of writing to file
Section titled “Print to stdout instead of writing to file”bunx prisma db pull --printpnpm prisma db pull --printyarn prisma db pull --printnpx prisma db pull --printForce overwrite existing schema
Section titled “Force overwrite existing schema”Ignore any customizations in the current schema:
bunx prisma db pull --forcepnpm prisma db pull --forceyarn prisma db pull --forcenpx prisma db pull --forceSet composite type depth for MongoDB
Section titled “Set composite type depth for MongoDB”bunx prisma db pull --composite-type-depth=2pnpm prisma db pull --composite-type-depth=2yarn prisma db pull --composite-type-depth=2npx prisma db pull --composite-type-depth=2