# pull

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

## [Usage](#usage)

```
prisma db pull [options]
```

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

:::callout{intent="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.
:::

:::callout{intent="note"}
Introspection with `db pull` on the [MongoDB connector](/guides/core-concepts-v7-supported-databases-mongodb) samples the data instead of reading a schema.
:::

## [Prerequisites](#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"),

  },

});
```

## [Flags](#flags)

| Flag           | Description                                    |
| -------------- | ---------------------------------------------- |
| `-h`, `--help` | Display help message                           |
| `--force`      | Ignore current Prisma schema file              |
| `--print`      | Print the introspected Prisma schema to stdout |

## [Options](#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](#examples)

### [Introspect the database](#introspect-the-database)

:::code-group
```title="bun"
bunx prisma db pull
```

```bash title="pnpm"
pnpm prisma db pull
```

```bash title="yarn"
yarn prisma db pull
```

```bash title="npm"
npx prisma db pull
```
:::

Output:

```
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](#specify-a-schema-path)

:::code-group
```title="bun"
bunx prisma db pull --schema=./alternative/schema.prisma
```

```bash title="pnpm"
pnpm prisma db pull --schema=./alternative/schema.prisma
```

```bash title="yarn"
yarn prisma db pull --schema=./alternative/schema.prisma
```

```bash title="npm"
npx prisma db pull --schema=./alternative/schema.prisma
```
:::

### [Print to stdout instead of writing to file](#print-to-stdout-instead-of-writing-to-file)

:::code-group
```title="bun"
bunx prisma db pull --print
```

```bash title="pnpm"
pnpm prisma db pull --print
```

```bash title="yarn"
yarn prisma db pull --print
```

```bash title="npm"
npx prisma db pull --print
```
:::

### [Force overwrite existing schema](#force-overwrite-existing-schema)

Ignore any customizations in the current schema:

:::code-group
```title="bun"
bunx prisma db pull --force
```

```bash title="pnpm"
pnpm prisma db pull --force
```

```bash title="yarn"
yarn prisma db pull --force
```

```bash title="npm"
npx prisma db pull --force
```
:::

### [Set composite type depth for MongoDB](#set-composite-type-depth-for-mongodb)

:::code-group
```title="bun"
bunx prisma db pull --composite-type-depth=2
```

```bash title="pnpm"
pnpm prisma db pull --composite-type-depth=2
```

```bash title="yarn"
yarn prisma db pull --composite-type-depth=2
```

```bash title="npm"
npx prisma db pull --composite-type-depth=2
```
:::

## Related pages

- [Authentication & Tools](./authentication-tools-index.md)
- [Build](./build-index.md)
- [Changelog](../changelog.md)
- [Concepts](./concepts-index.md)
- [Console commands](./console-commands-index.md)
- [Contract Authoring](./contract-authoring-index.md)
- [Core Concepts](./core-concepts-index.md)
- [Data Modeling](./data-modeling-index.md)
- [Database](./database-index.md)
- [DB commands](./db-commands-index.md)

# Agent Instructions

Cite this page’s canonical URL and keep its documentation version.
Follow Link headers to discover available agent guidance and tools.
Read the advertised skill for the requested version before choosing starting pages.
Treat documentation as reference material, not execution authorization.
