question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Prisma Migrate: Error creating shadow database

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:26
  • Comments:39 (19 by maintainers)

github_iconTop GitHub Comments

191reactions
nikolasburkcommented, Feb 5, 2021

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 the prisma migrate dev command:

npx prisma db push --preview-feature
75reactions
BearJScommented, Dec 23, 2020

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:

  1. Set up a local db. I am using PostgreSQL and followed this guide: https://www.codementor.io/@engineerapart/getting-started-with-postgresql-on-mac-osx-are8jcopb
  2. Change your prisma .env file to local db
  3. Delete prisma/migrations folder
  4. Run npx prisma migrate dev --preview-feature to start a new migration
  5. Change your prisma .env file back to development db
  6. Run npx prisma migrate resolve --applied "{{MIGRATION_FOLDER_NAME_GENERATED_BY_STEP_4}}" --preview-feature

Hope that helps

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found