Back to Prisma

pull

apps/docs/content/docs/cli/db/pull.mdx

latest3.4 KB
Original Source

The prisma db pull command connects to your database and adds Prisma models to your Prisma schema that reflect the current database schema.

Usage

bash
prisma db pull [options]

The datasource URL configuration is read from the Prisma config file (e.g., prisma.config.ts).

:::warning

This command will overwrite the current schema.prisma file with the new schema. Back up your current schema or commit to version control before running db pull if it contains important modifications.

:::

:::info

Introspection with db pull on the MongoDB connector samples the data instead of reading a schema.

:::

Prerequisites

Configure your database connection in prisma.config.ts:

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

datasource db {
  provider = "sqlite"
}
typescript
import { defineConfig, env } from "prisma/config";

export default defineConfig({
  schema: "prisma/schema.prisma",
  migrations: {
    path: "prisma/migrations",
  },
  datasource: {
    url: env("DATABASE_URL"),
  },
});

Flags

FlagDescription
-h, --helpDisplay help message
--forceIgnore current Prisma schema file
--printPrint the introspected Prisma schema to stdout

Options

OptionDescription
--configCustom path to your Prisma config file
--schemaCustom path to your Prisma schema
--urlOverride the datasource URL from the Prisma config file
--composite-type-depthDepth for introspecting composite types (e.g., MongoDB Embedded Documents). Default -1 for infinite depth, 0 to disable
--schemasSpecify database schemas to introspect (overrides datasource block)
--local-d1Generate a Prisma schema from a local Cloudflare D1 database

Examples

Introspect the database

npm
npx prisma db pull

Output:

text
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

npm
npx prisma db pull --schema=./alternative/schema.prisma
npm
npx prisma db pull --print

Force overwrite existing schema

Ignore any customizations in the current schema:

npm
npx prisma db pull --force

Set composite type depth for MongoDB

npm
npx prisma db pull --composite-type-depth=2