All guidesMore providers: databases, auth, hosting, email and payments
On this page

PlanetScale error

PlanetScale

Prisma P3022: Direct execution of DDL SQL statements is disabled on this database

By Ohad Krispin, founder of VibeRaven · LinkedIn

"Direct execution of DDL (Data Definition Language) SQL statements is disabled on this database" is Prisma error P3022. It means a schema statement such as CREATE or ALTER reached a PlanetScale (Vitess) branch that has safe migrations on. PlanetScale rejects DDL sent straight to such a branch, and prisma db push or prisma migrate sends exactly that when DATABASE_URL points at your production branch. Make the schema change on a development branch, open a deploy request into the production branch, and deploy it there. Do not run prisma db push or prisma migrate deploy in the Vercel build against the production branch. Turning safe migrations off also clears the error, but then DDL runs directly on production.

What is the raw MySQL error behind P3022?

Prisma's schema engine checks every MySQL error from a database it detects as Vitess. When the error code is 1105 and the message is exactly "direct DDL is disabled", it returns P3022 with the long message and a link to pris.ly/d/migrate-no-direct-ddl (schema-engine/connectors/sql-schema-connector/src/flavour/mysql/connector/native/mod.rs and libs/user-facing-errors/src/schema_engine.rs). The raw form is the title of Prisma issue 7385. PlanetScale's docs do not print the error text; they say DDL statements sent to a branch with safe migrations enabled are rejected, whether they come from a console, a terminal or a MySQL GUI.

Direct execution of DDL (Data Definition Language) SQL statements is disabled on this database. Please read more here about how to handle this: https://pris.ly/d/migrate-no-direct-ddl

ERROR HY000 (1105): direct DDL is disabled

How do I change the schema with a deploy request?

PlanetScale's Prisma tutorial uses this order: create a development branch from main, point DATABASE_URL at that branch, run prisma db push, open a deploy request, deploy it. The deploy request can only target a branch that has safe migrations on; if the "Deploy to" option is missing, the target branch does not have it enabled. A deploy joins a serial queue when other deploys are pending, and a normal deploy can be reverted for up to 30 minutes after it finishes.

pscale branch create <DATABASE_NAME> add-subtitle
pscale connect <DATABASE_NAME> add-subtitle --port 3309
# DATABASE_URL="mysql://root@127.0.0.1:3309/<DATABASE_NAME>"
npx prisma db push
pscale deploy-request create <DATABASE_NAME> add-subtitle
pscale deploy-request deploy <DATABASE_NAME> <DR_NUMBER>

Can I turn safe migrations off instead?

Yes, in the dashboard (the cog on the branch's infrastructure card) or with the pscale CLI. PlanetScale recommends safe migrations for all production branches, and its schema changes page says that without them your schema changes run directly on your production branch. The CLI commands apply only to Vitess.

pscale branch safe-migrations disable <DATABASE_NAME> <BRANCH_NAME>

Checklist

How to fix it, then check the fix

  1. 01
    Find what runs schema commands against the database in your deploy, such as a build script, a postinstall script or a CI step:
    grep -rnE "prisma (db push|migrate)" package.json vercel.json .github --include=*.json --include=*.yml --include=*.yaml
  2. 02Check which branch the DATABASE_URL in Vercel belongs to. A PlanetScale password only works on the branch it was created for, so a production password reaches the production branch.
  3. 03Remove the schema command from the Vercel build. Run it on a development branch instead, with DATABASE_URL pointing at that branch.
  4. 04
    Open a deploy request from the development branch and deploy it:
    pscale deploy-request create <DATABASE_NAME> <DEV_BRANCH>
    pscale deploy-request deploy <DATABASE_NAME> <DR_NUMBER>
  5. 05Check the fix: open the production branch in the PlanetScale dashboard and confirm the new column or table is in its schema, then redeploy on Vercel, which applies changed variables only to new deployments.

Related

Sources

Official docs behind this checklist

FAQ

FAQ for builders before launch

Should I use prisma migrate or prisma db push with PlanetScale?

Prisma recommends prisma db push. PlanetScale builds its own schema diff when a branch is merged, so the migration files that prisma migrate writes may not match the changes PlanetScale actually runs.

Does PlanetScale Postgres show this error?

Not for this reason. PlanetScale's Postgres branching docs say Postgres branches do not use deploy requests and that you make schema changes directly on each branch. The safe-migrations CLI commands apply only to Vitess.

Why does it work with my local database?

Usually the local DATABASE_URL points at a database or a development branch that accepts DDL, while the production variable in Vercel points at a branch with safe migrations on.