Drift detected right after introspection (and after applying first migration)
See original GitHub issueBug 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:
- Created 2 years ago
- Comments:20 (10 by maintainers)
Top GitHub Comments
I can confirm this bug. Thanks for detailed reproduction and providing the dump.
Thanks for the amazing reproduction and detective work figuring out what is going on - perfect input for us to fix this.