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.

Drift detected right after introspection (and after applying first migration)

See original GitHub issue

Bug description

Right after introspection, without making any changes to the database, when creating the first migration there is drift detected.

Funnily enough, even after continuing to generate and apply the first migration, subsequent migrations also complain that there is drift and want to reset the database over and over.

How to reproduce

Use the attached PostgreSQL structure, then:

yarn prisma introspect
yarn prisma generate
yarn prisma migrate dev --name init

This then outputs:

prisma migrate dev --name init
Environment variables loaded from .env
Prisma schema loaded from prisma/schema.prisma
Datasource "db": PostgreSQL database "test", schema "public" at "localhost:15432"

✔ Drift detected: Your database schema is not in sync with your migration history.

We need to reset the PostgreSQL database "test" at "localhost:15432".
Do you want to continue? All data will be lost. › (y/N)

Expected behavior

The initial migration is created without drift issues.

Prisma information

PostgreSQL structure: schema-postgres.sql.zip

Here’s my prisma.schema also, but you can easily produce it by running prisma introspect. schema.prisma.zip

And the first migration it generates: 20210411032551_init.zip

And the subsequent migration, which it can’t apply: 20210411032733_init2.zip

When trying to apply this second migration the error is:

prisma migrate dev --name init2
Environment variables loaded from .env
Prisma schema loaded from prisma/schema.prisma
Datasource "db": PostgreSQL database "test", schema "public" at "localhost:15432"

✔ Drift detected: Your database schema is not in sync with your migration history.

We need to reset the PostgreSQL database "test" at "localhost:15432".
Do you want to continue? All data will be lost. … yes

eThe following migration(s) have been applied:

migrations/
  └─ 20210411032551_init/
    └─ migration.sql
Error: Database error
Error querying the database: db error: ERROR: relation "idx_51688_draad_id" already exists
   0: migration_core::api::ApplyMigrations
             at migration-engine/core/src/api.rs:73

Environment & setup

  • OS: Mac OS
  • Database: PostgreSQL (running in local Docker container using postgres:13-alpine)
  • Node.js version: v14.16.0
  • Prisma version:
prisma               : 2.20.1
@prisma/client       : 2.20.1
Current platform     : darwin
Query Engine         : query-engine 60ba6551f29b17d7d6ce479e5733c70d9c00860e (at node_modules/@prisma/engines/query-engine-darwin)
Migration Engine     : migration-engine-cli 60ba6551f29b17d7d6ce479e5733c70d9c00860e (at node_modules/@prisma/engines/migration-engine-darwin)
Introspection Engine : introspection-core 60ba6551f29b17d7d6ce479e5733c70d9c00860e (at node_modules/@prisma/engines/introspection-engine-darwin)
Format Binary        : prisma-fmt 60ba6551f29b17d7d6ce479e5733c70d9c00860e (at node_modules/@prisma/engines/prisma-fmt-darwin)
Default Engines Hash : 60ba6551f29b17d7d6ce479e5733c70d9c00860e
Studio               : 0.365.0

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:20 (10 by maintainers)

github_iconTop GitHub Comments

3reactions
pantharshit00commented, Apr 12, 2021

I can confirm this bug. Thanks for detailed reproduction and providing the dump.

2reactions
janpiocommented, Apr 11, 2021

Thanks for the amazing reproduction and detective work figuring out what is going on - perfect input for us to fix this.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Chapter 6 Evolutionary Mechanisms II: Mutation, Genetic Drift ...
When population sizes are small, genetic drift can induce substantial deviations from theoretical predictions, but the effects of drift get smaller as ...
Read more >
Prisma Migrate limitations and known issues
The following limitations apply to Prisma Migrate. ... You call prisma migrate dev and Prisma Migrate detects drift in the database or a...
Read more >
Correcting Focus Drift in Live-Cell Microscopy
The first application of time-lapse imaging in living cells was reported over ... For example, exposure mistakes might not be discovered until weeks...
Read more >
US10503895B2 - Runtime non-intrusive container security ...
A first request to modify data in the persistent storage is detected. ... After breaching the security on one application and/or isolated guest, ......
Read more >
quantitative relationships between drift and upstream ... - JSTOR
QUANTITATIVE RELATIONSHIPS BETWEEN DRIFT AND UPSTREAM. MIGRATION OF GAMMARUS FOSSARUM KOCH, 1835. (Schlitz studies on productivity No. 27).
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