Prisma Migrate: Error creating shadow database
See original GitHub issueProblem
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
Issue Analytics
- State:
- Created 3 years ago
- Reactions:26
- Comments:39 (19 by maintainers)
Top Results From Across the Web
About the shadow database
Some development-focused commands for relational databases of Prisma Migrate use a second, temporary database: ... The shadow database is created and deleted ...
Read more >Error when migrating models to database Prisma
P3014 Prisma Migrate could not create the shadow database. Please make sure the database user has permission to create databases.
Read more >Impossible prisma (postgreSQL) schema migration
Hello all! I'm facing an issue while trying to migrate my prisma schema: Error: P3014 Prisma Migrate could not create the shadow database....
Read more >Automatic Prisma migrations
This document has been updated to include the recommended Prisma and PlanetScale workflow, specifically the recommendation to use prisma db ...
Read more >"@ronsj @supabase_io @prisma Nevermind. It works! I ...
Problem Users run into this issue if their database user has no privileges to create databases (MySQL / Postgres). This happens because Migrate...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I just want to add a quick note for folks coming here from googling the error message that if you are currently prototyping and not in production, and don’t care about the generated migration files, you can also run
prisma db push
instead of theprisma migrate dev
command:For anyone like me who is a newbie to databases and who are using a cloud-hosted db for development, you can fix by doing the following:
npx prisma migrate dev --preview-feature
to start a new migrationnpx prisma migrate resolve --applied "{{MIGRATION_FOLDER_NAME_GENERATED_BY_STEP_4}}" --preview-feature
Hope that helps