Setup
npx prisma init
Create schema, config and .env
npx prisma init --datasource-provider
<provider>
Pick the database provider
npx prisma init --url <url>
Set a custom datasource URL
npx prisma init --with-model
Add a sample User model
npx prisma init --output <path>
Where the client is generated
npx prisma version
CLI, client and engine versions
npx prisma version --json
Same, machine readable
npx prisma debug
Diagnostics for a bug report
Generate
npx prisma generate
Generate the client from the schema
npx prisma generate --watch
Regenerate on schema changes
npx prisma generate --generator <name>
Run only one generator
npx prisma generate --no-engine
Client without an engine (Accelerate, edge)
npx prisma generate --no-hints
Suppress hints and banners
npx prisma generate --allow-no-models
Generate even with no models
Migrate
npx prisma migrate dev
Apply schema changes in development
Uses a shadow database, detects drift, and may offer a reset.
npx prisma migrate dev --name <name>
Name the new migration
npx prisma migrate dev --create-only
Write the SQL, do not apply it
npx prisma migrate deploy
Apply pending migrations (prod, CI)
npx prisma migrate status
Compare migrations with the database
Exits with 1 on unapplied, failed or diverged migrations,
handy in CI.
npx prisma migrate reset
Drop data and reapply all migrations
Development only. Asks for confirmation unless --force.
npx prisma migrate reset --force
Reset without the prompt
npx prisma migrate resolve --applied
<migration>
Mark a migration as applied
npx prisma migrate resolve --rolled-back
<migration>
Mark a failed migration as rolled back
npx prisma migrate diff --from-<src>
--to-<src>
Compare two schema states
Sources: -empty, -schema, -migrations, -config-datasource.
npx prisma migrate diff --from-config-datasource
--to-schema <file> --script
SQL to move DB to schema
npx prisma migrate diff ... --exit-code
Exit 2 when there are changes
npx prisma migrate diff ... -o <file>
Write the diff to a file
Database
npx prisma db push
Sync schema to DB without migrations
npx prisma db push --accept-data-loss
Proceed despite data loss
npx prisma db push --force-reset
Reset the database first
npx prisma db pull
Introspect DB into the schema
Overwrites manual edits to the schema file.
npx prisma db pull --print
Print the schema, do not write
npx prisma db pull --force
Discard manual schema changes
npx prisma db seed
Run the configured seed script
npx prisma db seed -- <args>
Pass arguments to the seed file
npx prisma db execute --file <file.sql>
Run a SQL file on the database
npx prisma db execute --stdin
Run SQL from standard input