init

Set up a new Prisma project in the current directory

The prisma init command bootstraps a fresh Prisma project within the current directory.

Usage

prisma init [options]

The command creates a prisma directory containing a schema.prisma file. By default, the project is configured for local Prisma Postgres, but you can choose a different database using the --datasource-provider option.

Options

OptionDescription
-h, --helpDisplay help message
--dbProvision a fully managed Prisma Postgres database on the Prisma Data Platform
--datasource-providerDefine the datasource provider: postgresql, mysql, sqlite, sqlserver, mongodb, or cockroachdb
--generator-providerDefine the generator provider to use (default: prisma-client-js)
--preview-featureDefine a preview feature to use (can be specified multiple times)
--outputDefine Prisma Client generator output path
--urlDefine a custom datasource URL

Flags

FlagDescription
--with-modelAdd an example model to the created schema file

Examples

Set up a new Prisma project (default)

Sets up a new project configured for local Prisma Postgres:

npx prisma init

Specify a datasource provider

Set up a new project with MySQL as the datasource provider:

npx prisma init --datasource-provider mysql

Specify a generator provider

Set up a project with a specific generator provider:

npx prisma init --generator-provider prisma-client-js

Specify preview features

Set up a project with specific preview features enabled:

npx prisma init --preview-feature metrics

Multiple preview features:

npx prisma init --preview-feature views --preview-feature metrics

Specify a custom output path

Set up a project with a custom output path for Prisma Client:

npx prisma init --output ./generated-client

Specify a custom datasource URL

Set up a project with a specific database URL:

npx prisma init --url mysql://user:password@localhost:3306/mydb

Add an example model

Set up a project with an example User model:

npx prisma init --with-model

Provision a Prisma Postgres database

Create a new project with a managed Prisma Postgres database:

npx prisma init --db

This requires authentication with the Prisma Data Platform Console.

Generated files

After running prisma init, you'll have the following files:

prisma/schema.prisma

The Prisma schema file where you define your data model:

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

datasource db {
  provider = "postgresql"
}

prisma.config.ts

A TypeScript configuration file for Prisma:

import { defineConfig, env } from "prisma/config";

export default defineConfig({
  schema: "prisma/schema.prisma",
  migrations: {
    path: "prisma/migrations",
  },
  datasource: {
    url: env("DATABASE_URL"),
  },
});

.env

Environment variables file for your project:

DATABASE_URL="postgresql://user:password@localhost:5432/mydb"

.gitignore

Git ignore file configured for Prisma projects:

node_modules
.env
/generated/prisma

On this page