---
name: set-up-prisma-orm
description: Sets up Prisma ORM in a Node or TypeScript app, or repairs an existing app's database connection, by detecting the Prisma version first - new apps on Prisma 8, existing Prisma 6 or 7 apps kept on their version. Use when the user wants to add Prisma, connect Postgres or MySQL with an ORM, fix a Prisma connection error, or set up prisma.config.ts.
license: MIT
metadata:
  category: backend
  tags: "prisma,orm,postgres,typescript,nodejs"
  author: johnny-bravo
  version: "1.0"
  updated: "2026-10-31"
  status: published
  aliases: "prisma-orm-setup,prisma-setup"
  source_url: "https://github.com/prisma/skills/tree/8ea289b730c2e89f7ff1f518af128b113d842a92/prisma-orm-setup"
  source_license: MIT
  copyright: "Copyright (c) 2025 Prisma"
  original_author: "Prisma (prisma/skills, 'prisma-orm-setup')"
  modified: "Adapted by TheSkillVault: plain-language steps and a version decision list; PostgreSQL and client-setup references for Prisma 7 merged into one reference file; other providers linked upstream; added when-to-use, gotchas, safety, portability and done-when sections."
  imported_on: "2026-10-31"
---

# Set up Prisma ORM

Prisma ORM lets your code talk to a database with typed queries. The big trap is versions: Prisma 6, 7 and 8 set up differently. This skill finds out which one you have first, then follows the right path.

## When to use
- Adding a database layer with Prisma to a new or existing app.
- An existing Prisma app cannot connect to its database.
- The AI is mixing up Prisma 6, 7 and 8 instructions.

## Steps
1. **Detect the starting point.** Read `package.json`, the lockfile, `prisma/schema.prisma`, any `prisma.config.ts` and the imports in app code. Note the ORM version, the database and the runtime. The CLI version alone is not enough: check `@prisma/client` (and `@prisma/prisma7`) too.
   - Already on Prisma 8: skip to step 4. Do not re-initialise.
   - New app, no version chosen: go to step 3 (Prisma 8).
   - On Prisma 6 or 7, or the user chose an earlier major: go to step 5.
2. **Upgrades are a separate task.** Fixing a connection never needs a major upgrade. If the user asks for one, follow Prisma's official upgrade guide for that version and database.
3. **New app on Prisma 8.** Check the release's supported databases and runtime requirements first. If the database is not supported, say so and offer an earlier version; never quietly switch databases. Pin an exact Prisma 8 CLI release (do not trust a floating `latest`), then run it with the project's package manager. For Postgres with the Prisma schema language:
   ```bash
   prisma orm init --yes --target postgres --authoring psl
   ```
   Keep existing app files and connection settings. Do not let setup create a database the user did not ask for.
4. **Load the version's own guidance.** Run `prisma skills sync`, then read the synced `prisma-8/SKILL.md` (for example `.agents/skills/prisma-8/SKILL.md`) and follow it. Syncing alone does not load it. If it cannot be loaded, report that as a blocker.
5. **Earlier versions.** Pin every Prisma package to the same major.
   - **Prisma 7 with Postgres:** follow [references/prisma-7-postgresql.md](references/prisma-7-postgresql.md): driver adapter, `prisma.config.ts`, and the `prisma-client` generator with an `output` path.
   - **Prisma 7 with MySQL, SQLite, SQL Server or CockroachDB:** use the matching file in the upstream [references folder](https://github.com/prisma/skills/tree/8ea289b730c2e89f7ff1f518af128b113d842a92/prisma-orm-setup/references).
   - **Prisma 6:** keep its generator, schema URL and client setup. Use the Prisma 6 docs. Do not paste Prisma 7 config or adapters into it.
6. **Connect and verify.** Make sure the CLI and the app load the same environment file and point at the same database. Diagnose the connection before any schema-changing command. Run the project's checks and one read-only query through the app's client, such as a `count()`.

## Gotchas
- Installing packages or syncing skills is not a finished setup. Only a working read-only query is.
- The CLI and the app can read different `.env` files. A migration can then hit a different database than the app.
- Each `PrismaClient` opens a pool of connections. Create one and reuse it, or serverless apps run out of connections.
- Run `prisma generate` again after every schema change.

## Safety
- Keep `DATABASE_URL` and other credentials in a git-ignored `.env` or the host's secret settings. Never print them in logs or chat.
- Never run `migrate reset`, `db push --force-reset` or similar on a database with real data without a backup and a clear yes.
- For an existing app, keep its schema, migrations and generator config unless the task needs a change.

## Works with other stacks
Prisma supports PostgreSQL, MySQL, SQLite, SQL Server, CockroachDB and MongoDB, with npm, pnpm, yarn or bun. Using Drizzle or another ORM instead? The same rules apply: detect the version, keep secrets in env files, verify with a read-only query.

## Done when
- You can name the Prisma version in use and the database it connects to.
- A read-only query through the app's client returns a result, and the project's checks pass.

## Example prompt
"Add Prisma to my Next.js app and connect it to my Postgres database."

---
Adapted from "prisma-orm-setup" in prisma/skills by Prisma (MIT). See LICENSE.txt.
