The Prisma schema file (short: schema file, Prisma schema or schema) is the main configuration file for your Prisma setup. It is typically called schema.prisma and consists of the following parts:

  • Data sources: Specify the details of the data sources Prisma should connect to (e.g. a PostgreSQL database)
  • Generators: Specifies what clients should be generated based on the data model (e.g. Prisma Client)
  • Data model definition: Specifies your application models (the shape of the data per data source) and their relations

Whenever a prisma command is invoked, the CLI typically reads some information from the schema file, e.g.:

  • prisma generate: Reads all above mentioned information from the Prisma schema to generate the correct data source client code (e.g. Prisma Client).
  • prisma migrate save --experimental: Reads the data sources and data model definition to create a new migration.

You can also use environment variables inside the schema file to provide configuration options when a CLI command is invoked.


Here is an example for a Prisma schema file that specifies a data source (PostgreSQL), a generator (Prisma Client) and a data model definition with two models (with one relation) and one enum:

1datasource postgresql {
2 url = env("DATABASE_URL")
3 provider = "postgresql"
6generator client {
7 provider = "prisma-client-js"
10model User {
11 id Int @id @default(autoincrement())
12 createdAt DateTime @default(now())
13 email String @unique
14 name String?
15 role Role @default(USER)
16 posts Post[]
19model Post {
20 id Int @id @default(autoincrement())
21 createdAt DateTime @default(now())
22 updatedAt DateTime @updatedAt
23 published Boolean @default(false)
24 title String
25 author User? @relation(fields: [authorId], references: [id])
26 authorId Int?
29enum Role {


The default name for the schema file is schema.prisma. When your schema file is named like this, the Prisma CLI will detect it automatically in the directory where you invoke the CLI command (or any of its subdirectories).

If the file is named differently, you can provide the --schema argument to the Prisma CLI with the path to the schema file, e.g.:

1prisma generate --schema ./database/myschema.prisma


The schema file is written in Prisma Schema Language (PSL). You can find a full reference for PSL in the spec.

VS Code

Syntax highlighting for PSL is available via a VS Code extension (which also lets you auto-format the contents of your Prisma schema and indicates syntax errors with red squiggly lines). Learn more about setting up Prisma in your editor.


PSL code snippets on GitHub can be rendered with syntax highlighting as well by using the .prisma file extension or annotating fenced code blocks in Markdown with prisma:

2model User {
3 id Int @id @default(autoincrement())
4 createdAt DateTime @default(now())
5 email String @unique
6 name String?

Using environment variables

You can use environment variables to provide configuration options when a CLI command is invoked. Environment variables allow you to:

  • Keep secrets out of the schema file
  • Improve portability of the schema file

You can use machine-specific variables, .env files, or a combination of both.

Accessing environment variables from the schema

Environment variables can be accessed using the env function:

1datasource postgresql {
2 provider = "postgresql"
3 url = env("DATABASE_URL")

There are a few limitations with env at the moment:

  • It is not possible to use string concat operations (e.g. to construct your database connection string).
  • It is not possible to use environment variables for the provider argument in datasource and generator definitions.

Using .env files

For many developer tools, it has become a good practice to define environment variables using .env files. The Prisma CLI expects to find the .env file:

  1. Next to your schema file
  2. In the ./prisma folder, if it is not found next to your schema file

The following table describes where the Prisma CLI looks for the .env file:

CommandSchema file location.env file locations checked, in order
prisma [command]./prisma/schema.prisma./prisma/.env
prisma [command] --schema=./a/b/schema.prisma./a/b/schema.prisma./folder/subfolder/.env
prisma [command]No schema (for example, when running prisma introspect in an empty directory)./prisma/.env

Any environment variables defined in that .env file will automatically be loaded when running a Prisma CLI command.

Warning: Do not commit your .env files into version control.

Refer to the dotenv documentation for information about what happens if an environment variable is defined in two places.

Example: Set the DATABASE_URL environment variable in an .env file

It is common to load your database connection URL from an environment variable:

1// schema.prisma
2datasource db {
3 provider = "postgresql"
4 url = env("DATABASE_URL")

You can set the DATABASE_URL in your .env file:

1# .env

When you run a command that needs access the database defined via the datasource block (for example, prisma introspect), the Prisma CLI automatically loads the DATABASE_URL environment variables from the .env file and makes it available to the CLI.

Using environment variables in your code

If you want environment variables to be evaluated at runtime, you need to load them manually in your application code (for example, by using dotenv):

1import * as dotenv from 'dotenv'
3dotenv.config() // Load the environment variables
4console.log(`The connection URL is ${process.env.DATABASE_URL}`)

Manage .env files manually

You can use dotenv-cli if you want to:

  • Use multiple .env files
  • Use .env files from a location that the Prisma CLI does not check by default

Via command line

  1. Install dotenv-cli:

    1npm install -g dotenv-cli
  2. Create a file - for example, .env3 - in your project's root folder.

  3. To use the .env3 file, you can use dotenv when you run any Prisma command and specify which .env file to use. The following example uses a file named .env3:

    1dotenv -e .env3 npx prisma introspect

Via application code

  1. Add dotenv to your project:

    1npm install dotenv
  2. Create a file - for example, .env3 - in your project's root folder.

  3. To use the .env3 file, include a reference to dotenv at the top of your project's entry file.

    1import { config } from 'dotenv'
    2config({ path: '.env3' })


There are two types of comments that are supported in the schema file:

  • // comment: This comment is for the reader's clarity and is not present in the abstract syntax tree (AST) of the schema file.
  • /// comment: These comments will show up in the abstract syntax tree (AST) of the schema file, either as descriptions to AST nodes or as free-floating comments. Tools can then use these comments to provide additional information.

Here are some different examples:

1 /// This comment will get attached to the `User` node in the AST
2 model User {
3 /// This comment will get attached to the `id` node in the AST
4 id Int @default(autoincrement())
5 // This comment is just for you
6 weight Float /// This comment gets attached to the `weight` node
7 }
9 // This comment is just for you. It will not
10 // show up in the AST.
12 /// This is a free-floating comment that will show up
13 /// in the AST as a `Comment` node, but is not attached
14 /// to any other node. We can use these for documentation
15 /// in the same way that godoc.org works.
17 model Customer {}

Auto formatting

Similar to tools like gofmt and prettier, PSL syntax ships with a formatter for .prisma files. The formatter can be enabled in the VS Code extension.

Like gofmt and unlike prettier, there are no options for configuration here. There is exactly one way to format a prisma file.

Learn more about the formatting rules in the spec.

In this section

Edit this page on Github