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.

Migration failed to apply cleanly to the shadow database

See original GitHub issue

Bug description

After manually correcting a broken migration and committing it to the DB, I’m now getting the following error when I try to create a new migration with prisma migrate dev --create-only

Error: P3006

Migration `20220425205658_add_reference_to_model` failed to apply cleanly to the shadow database.
Error:
insert or update on table "reference" violates foreign key constraint "reference_model_id_fkey"
   0: sql_migration_connector::flavour::postgres::sql_schema_from_migration_history
             at migration-engine/connectors/sql-migration-connector/src/flavour/postgres.rs:354
   1: migration_core::api::DevDiagnostic
             at migration-engine/core/src/api.rs:108

But when I run prisma migrate status it returns Database schema is up to date!, so it shouldn’t be returning this error.

How to reproduce

Expected behavior

If a migration is successfully added to the DB, it shouldn’t still be returning errors.

Prisma information


datasource db {
  provider = "postgresql"
  url      = env("DATABASE_URL")
}

generator client {
  provider        = "prisma-client-js"
  previewFeatures = ["nativeTypes", "interactiveTransactions"]
  binaryTargets   = ["native", "rhel-openssl-1.0.x"]
}

Environment & setup

  • OS: MacOS 10.15.7
  • Database: PostgreSQL
  • Node.js version: v14.18.1

Prisma Version

3.4.2

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:15 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
jeremygottfriedcommented, Apr 30, 2022

Looks like that worked thanks!

1reaction
jeremygottfriedcommented, Apr 27, 2022

reference_model isn’t the actual name of my model. It’s just the name I’m using for examples. The names match in my actual migration

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error when migrating models to database Prisma
I tried Introspect. But, my DB currently has no tables and that threw an error. I tried npx prisma migrate save -experimental b/c...
Read more >
About the shadow database - Prisma
Important: The shadow database is not required in production, and is not used by production-focused commands such as prisma migrate resolve and prisma...
Read more >
Impossible prisma (postgreSQL) schema migration - Render
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 >
Shadow Database or Shadow Schema - Flyway
When setting the shadow database/schema connection, ensure it isn't an important database/schema as this may be cleaned and rebuilt when ...
Read more >
Understand the shadow database feature of Prisma ORM
When running a Prisma migration on a cloud-hosted database, you need a shadow database to see your migration succeed.
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 Reddit Thread

No results found

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