Skip to main content
The prisma init command creates the necessary files to start using Prisma ORM in your project.

Usage

npx prisma init

What it creates

The init command creates:
  1. prisma/schema.prisma - Prisma schema file with datasource and generator configuration
  2. prisma.config.ts - Prisma configuration file for connection and settings
  3. .env (if datasource requires it) - Environment file for database credentials

Options

--url
string
Database connection URL to use instead of prompting
--datasource-provider
string
Database provider to use: postgresql, mysql, sqlite, sqlserver, mongodb, cockroachdb
--generator-provider
string
Generator provider to use (default: prisma-client)
--output
string
Custom output directory for generated Prisma Client (default: ../generated/prisma)
--with-model
boolean
Include a sample User model in the schema
--db
boolean
Create a Prisma Postgres database (interactive flow)
--region
string
Region for Prisma Postgres database
--name
string
Name for Prisma Postgres database
--non-interactive
boolean
Run in non-interactive mode using provided flags
--preview-feature
string[]
Enable preview features (can be specified multiple times)

Examples

Basic initialization

Create a new Prisma project with interactive prompts:
npx prisma init

Initialize with specific database

Initialize with PostgreSQL:
npx prisma init --datasource-provider postgresql
Initialize with SQLite:
npx prisma init --datasource-provider sqlite

Initialize with connection URL

Skip the provider selection and use a specific database URL:
npx prisma init --url "postgresql://user:password@localhost:5432/mydb"

Initialize with sample model

Create the project with a sample User model:
npx prisma init --datasource-provider postgresql --with-model

Non-interactive initialization

Initialize without prompts (useful for CI/CD):
npx prisma init \
  --datasource-provider postgresql \
  --generator-provider prisma-client \
  --output ../generated/prisma \
  --non-interactive

Initialize with Prisma Postgres

Create a new Prisma Postgres database:
npx prisma init --db
This will:
  1. Prompt you to log in to Prisma
  2. Create a new database in your account
  3. Configure your project with the connection string
You can also specify database details:
npx prisma init --db --name my-app-db --region us-east-1

Generated schema file

The default schema file created by init:
// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema

generator client {
  provider = "prisma-client"
  output   = "../generated/prisma"
}

datasource db {
  provider = "postgresql"
}
With --with-model flag:
generator client {
  provider = "prisma-client"
  output   = "../generated/prisma"
}

datasource db {
  provider = "postgresql"
}

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

Generated config file

The prisma.config.ts file:
import { defineConfig, env } from 'prisma/config'

export default defineConfig({
  datasource: {
    url: env('DATABASE_URL'),
  },
})

Workflow

After running init, the typical workflow is:
1

Set up database connection

Update prisma.config.ts with your database URL or set the DATABASE_URL environment variable.
2

Define your data model

Edit prisma/schema.prisma to define your models.
3

Create migrations

Run npx prisma migrate dev to create and apply migrations.
4

Generate Prisma Client

Run npx prisma generate to generate the type-safe client.

Supported providers

The --datasource-provider flag accepts:
  • postgresql - PostgreSQL (9.6+)
  • mysql - MySQL (5.7+) and MariaDB (10.2+)
  • sqlite - SQLite (3.x)
  • sqlserver - Microsoft SQL Server (2017+)
  • mongodb - MongoDB (4.2+)
  • cockroachdb - CockroachDB (21.2.4+)

Error handling

The init command will not overwrite existing files. If prisma/schema.prisma or prisma.config.ts already exist, you’ll need to manually integrate the changes.

Next steps

Define your schema

Learn about Prisma Schema Language

Run migrations

Create your first migration

Generate Client

Generate your type-safe database client

Prisma Config

Configure your Prisma project