Repository navigation
Closed
Milestone
Description
Problem
Users run into this issue if their database user has no privileges to create databases (MySQL / Postgres). This happens because Migrate tries to create a shadow database under the hood.
> DATABASE_URL="postgres://prismatest:prismatest@localhost:5432/prismatest" npx prisma migrate dev --preview-feature
Environment variables loaded from prisma/.env
Prisma schema loaded from prisma/schema.prisma
Datasource "db": PostgreSQL database "prismatest", schema "public" at "localhost:5432"
2020-12-08 17:22:21.346 WET [11179] ERROR: relation "_prisma_migrations" does not exist at character 126
2020-12-08 17:22:21.346 WET [11179] STATEMENT: SELECT "id", "checksum", "finished_at", "migration_name", "logs", "rolled_back_at", "started_at", "applied_steps_count" FROM "_prisma_migrations" ORDER BY "started_at" ASC
2020-12-08 17:22:21.347 WET [11179] ERROR: permission denied to create database
2020-12-08 17:22:21.347 WET [11179] STATEMENT: CREATE DATABASE "prisma_migrations_shadow_database_8e443e23-bb18-4c98-8903-8777da7f625b"
Error: A migration failed when applied to the shadow database:
Database error: Error querying the database: db error: ERROR: permission denied to create database
0: sql_migration_connector::flavour::postgres::sql_schema_from_migration_history
at migration-engine/connectors/sql-migration-connector/src/flavour/postgres.rs:172
1: sql_migration_connector::sql_database_migration_inferrer::calculate_drift
at migration-engine/connectors/sql-migration-connector/src/sql_database_migration_inferrer.rs:59
2: migration_core::api::DiagnoseMigrationHistory
at migration-engine/core/src/api.rs:148
Some of the situations where this might be the case:
- Running DBMS locally but user has insufficient privileges -> Possible resolution: grant privileges. We should improve the user-facing error and document this properly
- Using a cloud-hosted DB for development, where creating additional databases is probably not supported -> Possible resolution: make the shadow DB URL configurable
Additional context
Reacted by Patrick Jakubik, Daniel Norman, Polad10, Darryl Young, v1rtl, Paweł Neubauer, Sid, Craig Spaeth, trip-sc, Cristian Rosescu and 26 more
Activity
Jolg42 commentedon Dec 10, 2020
You can find more info in our docs here https://www.prisma.io/docs/concepts/components/prisma-migrate#shadow-database

albertoperdomo commentedon Dec 16, 2020
User-facing error message (draft):
The link https://pris.ly/d/migrate-shadow should be added to Prisly and it can point to https://www.prisma.io/docs/concepts/components/prisma-migrate#shadow-database
add /d/migrate-shadow
Jolg42 commentedon Dec 16, 2020
https://pris.ly/d/migrate-shadow is live
Special-case shadow database creation errors
Special-case shadow database creation errors
Special-case shadow database creation errors
39 remaining items
AuthorOfTheSurf commentedon May 7, 2023
I ran into this while attempting to set up a redwood app with an app-specific database user:
I thought that this GRANT would be sufficient
But it doesn't actually grant CREATEDB to the
my_appuserI needed to hop back into
psqland use ALTER USDER:Can confirm that "Create DB" access has been granted with
\du:In the end I have a local postgres user called
my_appthat can do whatever it wants withmy_app_devdatabase. So I am not reliant on the top-level user calledpostgresor<machine_name>. This was my intentionP.S. Here is my connection string in case it may help anyone:
nzorg commentedon May 15, 2023
For anyone using MySQL, Prisma creates and drops a bunch of
prisma_migrate_shadow_db_[UUID]databases. So if your user only has access to the app DB it will fail. Assuming your user configured in .env is johndoe, this will work:I have a few issues with this. The command output is not clear at all, because it says "User johndoe was denied access on the database mydb", when in fact it had access to that db, but not to create other dbs. This should be better documented. And an even bigger concern, by allowing CREATE and DROP in all databases, we're compromising the security and not following least privilege principle. In MySQL there's no way to grant create and drop for a particular DB prefix, so the only way it can work is by allowing wildcard.
Jolg42 commentedon May 15, 2023
@n5sgg Thanks for the feedback. I think in this case, which is probably not obvious in our docs, you could use the
shadowDatabaseUrlproperty to define the shadow database name permanently. Meaning, you can then grant permissions for create and drop only for that database, eliminating the security risk of the wildcard.See https://www.prisma.io/docs/concepts/components/prisma-migrate/shadow-database#cloud-hosted-shadow-databases-must-be-created-manually
nzorg commentedon May 15, 2023
Thanks @Jolg42, it worked fine. I've created a hello-prisma repo using mysql and docker-compose in case this helps anyone: https://github.com/n5sgg/hello-prisma
LeCongNam commentedon May 30, 2023
if you using mysql with docker. you must using Account root. I'm don't know why Prisma required Root Account. If using DB from Cloud Share cannot not fix :) Prisma recomment you using command
janpio commentedon Jun 7, 2023
You do not need to use a
rootaccount. You just need to use an account that can executeCREATE DATABASE. Otherwise you can define theshadowDatabaseUrlto an already existing database.isaacgr commentedon Aug 14, 2023
Jolg42 commentedon Aug 14, 2023
isaacgr commentedon Aug 15, 2023
coderunner86 commentedon Jan 23, 2024
You can also run npx prisma db push
newerton commentedon Apr 10, 2024
I had the same problem with migration, downgrading to 5.9.1 worked.
Error with version (5.12.1, 5.12.0, 5.11.0, 5.10.2, 5.10.1 and 5.10.0)
Error log
Postgres: https://artifacthub.io/packages/helm/bitnami/postgresql
Version: 16.2.0
Prisma Version
ben-harris-5 commentedon Jun 11, 2024
@newerton I experienced the same issue too, and reverting to 5.9.1 also worked for me!
sadeeabdullah commentedon Nov 13, 2024
I was confronting the same issue.
Here is the solution (https://satisfyhost.com/blog/prisma-migrate-could-not-create-the-shadow-database/) that
i followed the blog and solved the problem in a moment.
Abdulrehman3802 commentedon Aug 12, 2025
If you encounter permission issues while creating a shadow database with Prisma, try adding this configuration in your
schema.prisma. This resolves the problem as some hosting providers restrict DB users from creating new databases. Thanks to @Jolg42 for the helpful tip!luiz00martins commentedon Nov 28, 2025
Broken link. I assume the new one is: https://www.prisma.io/docs/orm/prisma-migrate/understanding-prisma-migrate/shadow-database.