diff --git a/content/800-guides/010-data-migration.mdx b/content/800-guides/010-data-migration.mdx
index b0f223dc46..f8632988d7 100644
--- a/content/800-guides/010-data-migration.mdx
+++ b/content/800-guides/010-data-migration.mdx
@@ -137,6 +137,12 @@ Generate the migration:
npx prisma migrate dev --name add-status-column
```
+Then generate Prisma Client:
+
+```bash
+npx prisma generate
+```
+
## 3. Migrate the data
### 3.1. Create migration script
@@ -237,6 +243,12 @@ Create and run the final migration:
npx prisma migrate dev --name drop-published-column
```
+Then generate Prisma Client:
+
+```bash
+npx prisma generate
+```
+
## 5. Deploy to production
### 5.1. Set up deployment
diff --git a/content/800-guides/020-implementing-schema-changes.mdx b/content/800-guides/020-implementing-schema-changes.mdx
index 83a4f30211..c98f1c253e 100644
--- a/content/800-guides/020-implementing-schema-changes.mdx
+++ b/content/800-guides/020-implementing-schema-changes.mdx
@@ -169,6 +169,7 @@ And generates a migration:
```terminal
npx prisma migrate dev --name new-field
+npx prisma generate
```
### 3.2. Developer B's changes
@@ -186,6 +187,7 @@ And generates a migration:
```terminal
npx prisma migrate dev --name new-model
+npx prisma generate
```
### 3.3. Merge changes
@@ -224,6 +226,7 @@ Run the migrate command:
```terminal
npx prisma migrate dev
+npx prisma generate
```
This will:
diff --git a/content/800-guides/080-turborepo.mdx b/content/800-guides/080-turborepo.mdx
index 11b22c1ea7..0420f37b2f 100644
--- a/content/800-guides/080-turborepo.mdx
+++ b/content/800-guides/080-turborepo.mdx
@@ -364,7 +364,7 @@ Next, export the generated types and an instance of `PrismaClient` so it can use
In the `packages/database` directory, create a `src` folder and add a `client.ts` file. This file will define an instance of `PrismaClient`:
```ts file=packages/database/src/client.ts
-import { PrismaClient } from "../generated/prisma";
+import { PrismaClient } from "../generated/prisma/client";
import { PrismaPg } from '@prisma/adapter-pg';
const adapter = new PrismaPg({
@@ -384,8 +384,8 @@ if (process.env.NODE_ENV !== "production") globalForPrisma.prisma = prisma;
Then create an `index.ts` file in the `src` folder to re-export the generated prisma types and the `PrismaClient` instance:
```ts file=packages/database/src/index.ts
-export { prisma } from './client' // exports instance of prisma
-export * from "../generated/prisma" // exports generated types from prisma
+export { prisma } from './client' // exports instance of prisma
+export * from "../generated/prisma/client" // exports generated types from prisma
```
Follow the [Just-in-Time packaging pattern](https://turbo.build/repo/docs/core-concepts/internal-packages#just-in-time-packages) and create an entrypoint to the package inside `packages/database/package.json`:
diff --git a/content/800-guides/090-nextjs.mdx b/content/800-guides/090-nextjs.mdx
index 2c67c33c4a..44c876b65d 100644
--- a/content/800-guides/090-nextjs.mdx
+++ b/content/800-guides/090-nextjs.mdx
@@ -151,13 +151,20 @@ export default defineConfig({
});
```
-### 2.4. Configure the Prisma Client generator
+### 2.4. Run migrations and generate Prisma Client
-Now, run the following command to create the database tables and generate the Prisma Client:
+Now, run the following command to create the database tables:
```terminal
npx prisma migrate dev --name init
```
+
+Then generate Prisma Client:
+
+```terminal
+npx prisma generate
+```
+
### 2.5. Seed the database
Add some seed data to populate the database with sample users and posts.
@@ -165,7 +172,7 @@ Add some seed data to populate the database with sample users and posts.
Create a new file called `seed.ts` in the `prisma/` directory:
```typescript file=prisma/seed.ts
-import { PrismaClient, Prisma } from "../app/generated/prisma";
+import { PrismaClient, Prisma } from "../app/generated/prisma/client";
import { PrismaPg } from '@prisma/adapter-pg'
import 'dotenv/config'
@@ -285,7 +292,7 @@ Now, add the following code to your `lib/prisma.ts` file:
```typescript file=lib/prisma.ts showLineNumbers
//add-start
-import { PrismaClient } from '../app/generated/prisma'
+import { PrismaClient } from '../app/generated/prisma/client'
import { PrismaPg } from '@prisma/adapter-pg'
const globalForPrisma = global as unknown as {
diff --git a/content/800-guides/130-docker.mdx b/content/800-guides/130-docker.mdx
index caf402bcde..515235a77b 100644
--- a/content/800-guides/130-docker.mdx
+++ b/content/800-guides/130-docker.mdx
@@ -171,7 +171,7 @@ Add the following code to set up a basic Express server:
```js file=index.js
//add-start
const express = require("express");
-const { PrismaClient } = require("./generated/prisma_client");
+const { PrismaClient } = require("./generated/prisma_client/client");
const { PrismaPg } = require("@prisma/adapter-pg");
const adapter = new PrismaPg({
@@ -286,7 +286,13 @@ Run the migration to create the database schema:
npx prisma migrate dev --name init
```
-This should generate a `migrations` folder in the `prisma` folder.
+Then generate Prisma Client:
+
+```terminal
+npx prisma generate
+```
+
+This should generate a `migrations` folder in the `prisma` folder and the Prisma Client in the `generated/prisma_client` directory.
### 2.4. Test the application
diff --git a/content/800-guides/150-multiple-databases.mdx b/content/800-guides/150-multiple-databases.mdx
index 6b65082464..3fe59fb5c6 100644
--- a/content/800-guides/150-multiple-databases.mdx
+++ b/content/800-guides/150-multiple-databases.mdx
@@ -93,7 +93,7 @@ The `prisma@latest init --db` command:
- Connects your CLI to your [Prisma Data Platform](https://console.prisma.io) account. If you are not logged in or do not have an account, your browser will open to guide you through creating a new account or signing into your existing one.
- Creates a `prisma` directory containing a `schema.prisma` file for your database models.
-- Creates a `.env` file with your `DATABASE_URL` (e.g., for Prisma Postgres it should have something similar to `DATABASE_URL="prisma+postgres://accelerate.prisma-data.net/?api_key=eyJhbGciOiJIUzI..."`).
+- Creates a `.env` file with your `DATABASE_URL` (e.g., `DATABASE_URL="postgresql://user:password@host:5432/database?sslmode=require"`).
Rename the `prisma` folder to `prisma-user-database`:
@@ -105,10 +105,10 @@ Edit your `.env` file to rename `DATABASE_URL` to `PPG_USER_DATABASE_URL`:
```text file=.env
//delete-start
-DATABASE_URL="prisma+postgres://accelerate.prisma-data.net/?api_key=eyJhbGciOiJIUzI...
+DATABASE_URL="postgresql://user:password@host:5432/database?sslmode=require"
//delete-end
//add-start
-PPG_USER_DATABASE_URL="prisma+postgres://accelerate.prisma-data.net/?api_key=eyJhbGciOiJIUzI...
+PPG_USER_DATABASE_URL="postgresql://user:password@host:5432/database?sslmode=require"
//add-end
```
@@ -184,10 +184,10 @@ Rename the `DATABASE_URL` variable in `.env` to `PPG_POST_DATABASE_URL`:
```text file=.env
//delete-start
-DATABASE_URL="prisma+postgres://accelerate.prisma-data.net/?api_key=eyJhbGciOiJIUzI...
+DATABASE_URL="postgresql://user:password@host:5432/database?sslmode=require"
//delete-end
//add-start
-PPG_POST_DATABASE_URL="prisma+postgres://accelerate.prisma-data.net/?api_key=eyJhbGciOiJIUzI...
+PPG_POST_DATABASE_URL="postgresql://user:password@host:5432/database?sslmode=require"
//add-end
```
@@ -287,7 +287,7 @@ In `lib/user-prisma-client.ts`, add the following code:
```ts file=lib/user-prisma-client.ts
//add-start
-import { PrismaClient } from "../prisma-user-database/user-database-client-types";
+import { PrismaClient } from "../prisma-user-database/user-database-client-types/client";
import { PrismaPg } from "@prisma/adapter-pg";
const adapter = new PrismaPg({
@@ -316,7 +316,7 @@ In `lib/post-prisma-client.ts`, add this code:
```ts file=lib/post-prisma-client.ts
//add-start
-import { PrismaClient } from "../prisma-post-database/post-database-client-types";
+import { PrismaClient } from "../prisma-post-database/post-database-client-types/client";
import { PrismaPg } from "@prisma/adapter-pg";
const adapter = new PrismaPg({
diff --git a/content/800-guides/160-tanstack-start.mdx b/content/800-guides/160-tanstack-start.mdx
index 1dd47c3004..719d3de79e 100644
--- a/content/800-guides/160-tanstack-start.mdx
+++ b/content/800-guides/160-tanstack-start.mdx
@@ -397,6 +397,7 @@ Now, run the following command to create the database tables and generate the Pr
```terminal
npx prisma migrate dev --name init
+npx prisma generate
```
### 2.5. Seed the database
diff --git a/content/800-guides/170-react-router-7.mdx b/content/800-guides/170-react-router-7.mdx
index 473ddc1d3d..2118a4b566 100644
--- a/content/800-guides/170-react-router-7.mdx
+++ b/content/800-guides/170-react-router-7.mdx
@@ -136,6 +136,7 @@ Now, run the following command to create the database tables and generate the Pr
```terminal
npx prisma migrate dev --name init
+npx prisma generate
```
### 2.5. Seed the database
diff --git a/content/800-guides/180-solid-start.mdx b/content/800-guides/180-solid-start.mdx
index 98a83742bd..dc2076e4c3 100644
--- a/content/800-guides/180-solid-start.mdx
+++ b/content/800-guides/180-solid-start.mdx
@@ -157,6 +157,7 @@ Now, run the following command to create the database tables and generate the Pr
```terminal
npx prisma migrate dev --name init
+npx prisma generate
```
### 2.5. Seed the database
diff --git a/content/800-guides/190-data-dog.mdx b/content/800-guides/190-data-dog.mdx
index c87815ba5b..28785285a3 100644
--- a/content/800-guides/190-data-dog.mdx
+++ b/content/800-guides/190-data-dog.mdx
@@ -80,18 +80,7 @@ Run the following commands to install Prisma and a minimal TypeScript runner:
npm install -D prisma tsx
```
-Then initialize Prisma:
-
-:::note
-
-You can use the `--db` flag to create a [new Prisma Postgres](/postgres) instance when initializing Prisma in your project.
-
-:::
-
-
-
-
-
+Then initialize Prisma with the `--db` flag to create a [new Prisma Postgres](/postgres) instance:
```terminal
npx prisma init --db --output ../src/generated/prisma
@@ -102,43 +91,20 @@ npx prisma init --db --output ../src/generated/prisma
You will be prompted to name your database and select the closest region. For clarity, choose a memorable name (e.g., `My Datadog Project`).
:::
-
-
-
-```terminal
-npx prisma init --output ../src/generated/prisma
-```
-
-
-
-
This command does the following:
-- Creates a `prisma` directory with a `schema.prisma` file.
+- Creates a `prisma` directory with a `schema.prisma` file.
- Generates the Prisma Client in the `/src/generated/prisma` directory (as specified in the `--output` flag).
-- Creates a `.env` file at the project root with your database connection string (`DATABASE_URL`).
+- Creates a `.env` file at the project root with your database connection string (`DATABASE_URL`).
-If you did not use the `--db` flag, replace the placeholder database URL in the `.env` file:
-
-
-
+The `.env` file should contain a standard connection string:
```bash file=.env
-DATABASE_URL="prisma+postgres://accelerate.prisma-data.net/?api_key=..."
+# Placeholder url you have to replace
+DATABASE_URL="postgresql://janedoe:mypassword@localhost:5432/mydb?schema=sample"
```
-
-
-
-```bash file=.env
-# Placeholder url you have to replace
-DATABASE_URL="postgresql://janedoe:mypassword@localhost:5432/mydb?schema=sample"
-```
-
-
-
-
Install the driver adapter for PostgreSQL:
```terminal
@@ -289,7 +255,7 @@ Create a `src/client.ts` to hold your Prisma Client instantiation:
```ts file=src/client.ts
import { tracer } from "./tracer";
-import { PrismaClient } from "./generated/prisma";
+import { PrismaClient } from "./generated/prisma/client";
import { PrismaPg } from "@prisma/adapter-pg";
const adapter = new PrismaPg({
diff --git a/content/800-guides/190-sveltekit.mdx b/content/800-guides/190-sveltekit.mdx
index 0d05d84226..f7f4bcf605 100644
--- a/content/800-guides/190-sveltekit.mdx
+++ b/content/800-guides/190-sveltekit.mdx
@@ -150,6 +150,7 @@ Now, run the following command to create the database tables and generate the Pr
```terminal
npx prisma migrate dev --name init
+npx prisma generate
```
### 2.5. Seed the database
diff --git a/content/800-guides/200-clerk-nextjs.mdx b/content/800-guides/200-clerk-nextjs.mdx
index 578c73316f..2abf74bfe4 100644
--- a/content/800-guides/200-clerk-nextjs.mdx
+++ b/content/800-guides/200-clerk-nextjs.mdx
@@ -313,6 +313,7 @@ Now, run the following command to create the database tables and generate the Pr
```terminal
npx prisma migrate dev --name init
+npx prisma generate
```
:::warning
@@ -327,7 +328,7 @@ In the root directory, create a `lib` directory and a `prisma.ts` file inside it
```tsx file=lib/prisma.ts showLineNumbers
//add-start
-import { PrismaClient } from "../app/generated/prisma";
+import { PrismaClient } from "../app/generated/prisma/client";
import { PrismaPg } from "@prisma/adapter-pg";
const adapter = new PrismaPg({
diff --git a/content/800-guides/210-shopify.mdx b/content/800-guides/210-shopify.mdx
index 81c9e4afa9..6a4b4e612b 100644
--- a/content/800-guides/210-shopify.mdx
+++ b/content/800-guides/210-shopify.mdx
@@ -76,8 +76,6 @@ datasource db {
provider = "postgresql"
//delete-next-line
url = "file:../dev.db"
- //add-next-line
- url = env("DATABASE_URL")
}
model Session {
@@ -126,7 +124,6 @@ generator client {
datasource db {
provider = "postgresql"
- url = env("DATABASE_URL")
}
model Session {
@@ -146,9 +143,16 @@ model ProductNote {
Next, Prisma will need to be updated to the latest version. Run:
```terminal
-npm install prisma --save-dev && npm install @prisma/client
+npm install prisma @types/pg --save-dev
+npm install @prisma/client @prisma/adapter-pg pg
```
+:::info
+
+If you are using a different database provider (MySQL, SQL Server, SQLite), install the corresponding driver adapter package instead of `@prisma/adapter-pg`. For more information, see [Database drivers](/orm/overview/databases/database-drivers).
+
+:::
+
Prisma Postgres allows you to create a new database on the fly, you can create a new database at the same time you initialize your project by adding the `--db` flag:
```terminal
@@ -158,37 +162,55 @@ npx prisma init --db
Once you've completed the prompts, it's time to access your new database:
1. **Open the [Prisma Console](https://console.prisma.io):**
- - Log in and find your newly created database project.
-2. **Set up your database credentials:**
- - In the sidebar, click **Database**, then select **Setup**.
- - Choose **Existing project** and press **Generate database credentials**.
-3. **Configure your environment:**
- - Create a new `.env` file in the root of your project.
- - Copy and paste the `DATABASE_URL` you just generated into this file. It should look similar to this:
+ - Log in and select your newly created database project.
+2. **Get your database connection string:**
+ - Click the **Connect** button.
+ - Copy the connection string that appears. It should look similar to this:
```env
- DATABASE_URL="prisma+postgres://accelerate.prisma-data.net/?api_key=..."
+ DATABASE_URL="postgresql://user:password@host:5432/database?sslmode=require"
```
+3. **Configure your environment:**
+ - Create a new `.env` file in the root of your project.
+ - Paste the `DATABASE_URL` you just copied into this file.
4. **Apply your database schema:**
- Run the following command to create your tables and get your database ready:
```terminal
npx prisma migrate dev --name init
```
-Now, before moving on, let's update your `db.server.ts` file to use the newly generated Prisma client.
+ Then generate Prisma Client:
+ ```terminal
+ npx prisma generate
+ ```
+
+Now, before moving on, let's update your `db.server.ts` file to use the newly generated Prisma client with the driver adapter:
```tsx file=app/db.server.ts
-//delete-next-line
+//delete-start
import { PrismaClient } from "@prisma/client";
-//add-next-line
+//delete-end
+//add-start
import { PrismaClient } from "./generated/prisma/client.js";
+import { PrismaPg } from "@prisma/adapter-pg";
+
+const adapter = new PrismaPg({
+ connectionString: process.env.DATABASE_URL,
+});
+//add-end
if (process.env.NODE_ENV !== "production") {
if (!global.prismaGlobal) {
+ //delete-next-line
global.prismaGlobal = new PrismaClient();
+ //add-next-line
+ global.prismaGlobal = new PrismaClient({ adapter });
}
}
+//delete-next-line
const prisma = global.prismaGlobal ?? new PrismaClient();
+//add-next-line
+const prisma = global.prismaGlobal ?? new PrismaClient({ adapter });
export default prisma;
```
diff --git a/content/800-guides/220-astro.mdx b/content/800-guides/220-astro.mdx
index 8ea3706ab3..836ec1580d 100644
--- a/content/800-guides/220-astro.mdx
+++ b/content/800-guides/220-astro.mdx
@@ -43,6 +43,12 @@ npx create-astro@latest
:::
+Navigate into the newly created project directory:
+
+```terminal
+cd astro-prisma
+```
+
## 2. Install and Configure Prisma
### 2.1. Install dependencies
@@ -131,13 +137,20 @@ export default defineConfig({
});
```
-### 2.4. Configure the Prisma Client generator
+### 2.4. Run migrations and generate Prisma Client
-Now, run the following command to create the database tables and generate the Prisma Client:
+Now, run the following command to create the database tables:
```terminal
npx prisma migrate dev --name init
```
+
+Then generate Prisma Client:
+
+```terminal
+npx prisma generate
+```
+
### 2.5. Seed the database
Let's add some seed data to populate the database with sample users and posts.
@@ -145,7 +158,7 @@ Let's add some seed data to populate the database with sample users and posts.
Create a new file called `seed.ts` in the `prisma/` directory:
```typescript file=prisma/seed.ts
-import { PrismaClient, Prisma } from "../prisma/generated/client.js";
+import { PrismaClient, Prisma } from "../prisma/generated/client";
import { PrismaPg } from "@prisma/adapter-pg";
const adapter = new PrismaPg({
@@ -365,6 +378,18 @@ const users: UserWithPosts[] = await response.json();