Prisma ORM 8 is here.Read the docs

orm init

Initialize Prisma ORM files in a project.

orm init scaffolds the Prisma ORM config, contract source, and runtime files inside an existing project, installs dependencies, and emits the contract. It gets you from zero to typed queries in one step.

Use a Prisma ORM quickstart when you want a complete new application template. Use orm init when you already have a project and want to add the lower-level Prisma ORM files.

Usage

Run it interactively for a guided setup:

bunx prisma@latest orm init

Or supply --target and --authoring for a fully scriptable run (CI, AI coding agents, automation):

bunx prisma@latest orm init --yes --target postgres --authoring psl

Options

OptionWhat it does
--target <db>Sets the database target. Use postgres or mongodb.
--authoring <style>Sets the contract authoring style. Use psl or typescript.
--schema-path <path>Sets where the starter contract is written.
--write-envWrites .env from .env.example (gitignored).
--probe-dbConnects to DATABASE_URL once and checks the server version.
--strict-probeTreats a failed database probe as fatal.
--skip-installSkips dependency installation and contract emission.
--keep-previous-facadeKeeps the previous target package in package.json when switching targets.

What it creates

The exact files depend on the target and authoring style, but a Postgres PSL setup normally includes:

  • prisma.config.ts
  • a starter contract file such as src/prisma/contract.prisma
  • emitted contract artifacts after installation runs
  • a runtime client file (src/prisma/db.ts) that imports contract.json
  • .env.example, tsconfig.json, and updated package.json
  • prisma-8.md, a short quick reference for writing your first typed query

The install step adds the target package to dependencies, and prisma@latest plus the matching @prisma/cli-engine to devDependencies.

The runtime files are ES modules. If your package.json declares "type": "commonjs", orm init keeps it and prints a warning. Set "type": "module" so the scaffolded db.ts loads.

The generated prisma.config.ts imports definePrismaConfig from @prisma/cli-engine, while projects created by create-prisma (and the examples in Configuration) import it from prisma/config. Both work; keep the import your project already has when you copy a config example.

Examples

bunx prisma@latest orm init --yes --target postgres --authoring psl
bunx prisma@latest orm init --yes --target mongodb --authoring typescript --json
bunx prisma@latest orm init --skip-install

After initialization

Review the generated files, set DATABASE_URL, and emit the contract when you change the schema:

bunx prisma@latest contract emit

Then initialize or verify the database:

bunx prisma@latest db init --db "$DATABASE_URL"
bunx prisma@latest db verify --db "$DATABASE_URL"

The scaffolded db.ts reads DATABASE_URL from the process environment at runtime. The CLI loads .env through the config file, but your own scripts do not. Run them with the variable set, for example node --env-file=.env src/index.ts.

On this page