Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

First identify whether PostgreSQL is empty or already contains tables, then choose the Prisma major version. This guide gives the documented Prisma ORM 7 PostgreSQL setup for a new or empty database. If your database is populated, use Prisma’s introspection workflow instead of creating a fresh schema over it. Prisma’s current documentation describes ORM 8 as a release candidate and says ORM 7 remains supported, so keep version-specific commands separate.

Choose the right setup path

Your situation Use this route
New app or empty PostgreSQL database Define Prisma models and create tables with the migration workflow for your chosen Prisma version. See Prisma’s PostgreSQL quickstart.
Existing Node.js app with an empty database Add Prisma configuration to the app you already have, then create tables. See Prisma’s guide for adding Prisma and PostgreSQL to an existing app.
Existing app with tables already in PostgreSQL Introspect the database schema and work against a development copy. Follow the existing PostgreSQL project workflow.
Prisma ORM 7 project Use the v7 command names and PostgreSQL driver adapter shown below.
Prisma ORM 8 trial Follow the current ORM 8 documentation from end to end; do not mix its commands with the v7 walkthrough.

Prisma’s current PostgreSQL documentation identifies ORM 8 as a release candidate, while ORM 7 is still supported. The guide below deliberately covers ORM 7, whose documented PostgreSQL setup uses prisma init, prisma migrate dev, prisma generate, and the @prisma/adapter-pg adapter. Check the selected version’s current documentation for prerequisites and syntax before adopting it.

What you need before you start

  • A Node.js project and its package manager. The Prisma ORM 7 quickstart uses a TypeScript project; if you use JavaScript or another project layout, adapt the example files and imports accordingly.
  • A running PostgreSQL server reachable from the app. Have its host, port, username, password, and database name available.
  • Permission to create or modify a schema if you are creating tables. For a populated database, use a development copy and the introspection path rather than experimenting against production.
  • A decision to use Prisma ORM 7 for the commands in this walkthrough. Prisma’s current ORM 8 pages describe a release candidate and use changed setup terminology.

Add Prisma ORM 7 to a new or empty-database app

The following sequence follows Prisma’s documented ORM 7 PostgreSQL pattern. It assumes an ESM TypeScript project and an empty database, or one where creating the model’s tables is intended. It is not a universal recipe for ORM 8, nor for a database whose existing schema must be preserved.

1. Install Prisma and the PostgreSQL adapter

Install the Prisma CLI, client, PostgreSQL adapter, PostgreSQL driver, and environment-variable loader:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Elebase USB to USB C Adapter for iPhone 18 Pro Max,USBC Car Charger Adapter
  • Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
  • Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
  • Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
  • Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
  • 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.
npm install prisma @prisma/client @prisma/adapter-pg pg dotenv

The v7 guide also includes TypeScript tooling and type packages for its TypeScript example. Add or retain the development dependencies appropriate to your project. Use package versions compatible with the Prisma major version you selected; the official Prisma ORM 7 PostgreSQL quickstart is the reference for its current package instructions.

2. Initialize Prisma and configure the connection

Initialize the v7 PostgreSQL setup from the project root:

npx prisma init --datasource-provider postgresql

Keep the database URL in an environment file rather than putting credentials in source code. A typical .env entry uses placeholders like these; replace them locally with the connection details for your database and do not commit real secrets:

Rank #2
Anker USB-C Hub, 5-in-1 USB Hub for Laptops, 4K HDMI Multiport Adapter
  • 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
  • 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
  • Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
  • 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
  • What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.
DATABASE_URL="postgresql://USER:PASSWORD@HOST:PORT/DATABASE?schema=public"

In the v7 setup, the datasource provider belongs in prisma/schema.prisma, while datasource configuration is handled through the Prisma config file and the URL is loaded from .env. Preserve the generated config and schema paths unless your project intentionally uses a different layout. If your provider or database uses a different schema name, configure it deliberately rather than assuming public.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

3. Define a Prisma model

Add a model to prisma/schema.prisma. For example, a small application that needs users could begin with:

model User {
  id    Int    @id @default(autoincrement())
  email String @unique
  name  String?
}

This model describes the fields and constraints Prisma will map to the database. Use model names and fields that fit your application; do not add this example to a database if doing so would conflict with existing tables or schema objects.

Rank #3
Sale
Anker USB C Hub, 7in1 Multi-Port USB Adapter, 4K@60Hz USBC to HDMI Splitter
  • Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
  • Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
  • Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
  • Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
  • What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.

4. Create the table with a development migration

For the ORM 7 empty-database flow, create and apply an initial development migration:

npx prisma migrate dev --name init

This command belongs to the v7 workflow described here. Review the migration before using it in a production deployment process; a development migration command is not a substitute for a deliberate production migration procedure.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

5. Generate Prisma Client

Generate the client for the schema:

npx prisma generate

Run generation after changing the Prisma schema so the client API corresponds to the models your code uses. Confirm the output and import path against the project’s generated setup.

Rank #4
Sale
UGREEN USB to USB C Adapter Combo 4-Pack, 10Gbps USB C Converter Space Gray
  • Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
  • Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
  • Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
  • Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
  • Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft

6. Instantiate Prisma Client with the PostgreSQL adapter

Prisma ORM 7’s documented PostgreSQL setup creates a PrismaPg adapter using the connection string, then passes that adapter to PrismaClient. A TypeScript example is:

import "dotenv/config";
import { PrismaPg } from "@prisma/adapter-pg";
import { PrismaClient } from "@prisma/client";

const connectionString = process.env.DATABASE_URL;
if (!connectionString) {
  throw new Error("DATABASE_URL is not set");
}

const adapter = new PrismaPg({ connectionString });
export const prisma = new PrismaClient({ adapter });

Place this in a module your application can import, such as src/lib/prisma.ts, adjusting the path for your project. Loading dotenv/config makes the local environment variable available in this example. Do not log or expose the URL because it contains credentials.

7. Run a first query

Import the client module and query the model defined in the schema. For example:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Best Value
Anker USB C Hub, 5-in-1 USBC to HDMI Splitter with 4K Display
  • 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
  • Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
  • Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
  • HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
  • What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.
const users = await prisma.user.findMany();
console.log(users);

Run the query from application code after the database is reachable and the migration has created the table. In a long-running app, manage the client as a shared application resource rather than constructing a new client for every request.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

If PostgreSQL already has tables

Do not start by treating a populated database as empty and applying the example model migration. Prisma’s existing-project guide describes a different workflow: add Prisma to the app, introspect the PostgreSQL schema, then make changes through the steps appropriate to that existing project. Use a development copy so introspection and subsequent changes do not risk production data. Begin with Prisma’s instructions for an existing PostgreSQL project.

Introspection generates Prisma schema definitions from the database’s current structure. Check those definitions against your application’s intended naming and relationships before writing queries or making schema changes. The empty-database migration example above is for creating tables from models, not for adopting an existing schema.

What changes if you choose Prisma ORM 8?

Prisma’s current documentation describes ORM 8 as a release candidate and ORM 7 as supported. The ORM 8 documentation changes setup and migration terminology: it refers to contract emit in place of v7’s prisma generate, and migration planning and application in place of the v7 migrate dev flow. Those differences are a reason to use the ORM 8 guide as a complete version-specific route, not to copy v7 commands into an ORM 8 project. See the current PostgreSQL quickstart and Prisma’s from-scratch setup guide.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Fix common setup problems

  • Connection failures: Check that DATABASE_URL is present in the environment where the app or Prisma command runs, and verify the host, port, database name, credentials, and network access.
  • Prisma cannot find the schema or config: Run commands from the expected project root and confirm the paths match the initialized Prisma layout. If you deliberately moved the config or schema, use the corresponding documented configuration.
  • Adapter-related errors in ORM 7: Confirm both @prisma/adapter-pg and pg are installed, and that the adapter instance is passed to new PrismaClient({ adapter }).
  • Client imports or model methods are missing: Run npx prisma generate after schema edits, then confirm the generated client import and model name match your code.
  • Commands behave differently than the guide: Check the installed Prisma major version and follow only that version’s documentation. In particular, this article’s initialization, migration, generation, and adapter instructions are for ORM 7.
  • A migration would collide with existing tables: Stop rather than applying an empty-database migration. Switch to the existing-database introspection workflow and work against a development copy.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.