prisma init command creates the necessary files to start using Prisma ORM in your project.
Usage
What it creates
Theinit command creates:
prisma/schema.prisma- Prisma schema file with datasource and generator configurationprisma.config.ts- Prisma configuration file for connection and settings.env(if datasource requires it) - Environment file for database credentials
Options
Database connection URL to use instead of prompting
Database provider to use:
postgresql, mysql, sqlite, sqlserver, mongodb, cockroachdbGenerator provider to use (default:
prisma-client)Custom output directory for generated Prisma Client (default:
../generated/prisma)Include a sample User model in the schema
Create a Prisma Postgres database (interactive flow)
Region for Prisma Postgres database
Name for Prisma Postgres database
Run in non-interactive mode using provided flags
Enable preview features (can be specified multiple times)
Examples
Basic initialization
Create a new Prisma project with interactive prompts:Initialize with specific database
Initialize with PostgreSQL:Initialize with connection URL
Skip the provider selection and use a specific database URL:Initialize with sample model
Create the project with a sample User model:Non-interactive initialization
Initialize without prompts (useful for CI/CD):Initialize with Prisma Postgres
Create a new Prisma Postgres database:- Prompt you to log in to Prisma
- Create a new database in your account
- Configure your project with the connection string
Generated schema file
The default schema file created byinit:
--with-model flag:
Generated config file
Theprisma.config.ts file:
Workflow
After runninginit, the typical workflow is:
Set up database connection
Update
prisma.config.ts with your database URL or set the DATABASE_URL environment variable.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
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