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.

`migrate dev --create-only` with empty schema but existing database schema detects drift and warns about deleting all data

See original GitHub issue

Bug description

  • No modesl in schema.prisma
  • 1 table in database schema
  • Running migrate dev --create-only gives following output:
PS C:\Users\piotr\Documents\serverless-prisma\demo> npx prisma migrate dev --create-only
Environment variables loaded from .env
Prisma schema loaded from prisma\schema.prisma
Datasource "db": PostgreSQL database "tests", schema "public" at "localhost:5432"

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

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

√ Name of migration ... init
Prisma Migrate created the following migration without applying it 20210414181550_init

You can now edit it and apply it by running prisma migrate dev.

--create-only needing to reset my database, and supposedly even doing that, was unexpected.

Expected behavior

No changes on data or warnings that indicate that when using --create-only.

Prisma information

PS C:\Users\piotr\Documents\serverless-prisma\demo> npx prisma -v
Environment variables loaded from .env
prisma               : 2.21.1
@prisma/client       : 2.21.1
Current platform     : windows
Query Engine         : query-engine e421996c87d5f3c8f7eeadd502d4ad402c89464d (at node_modules\@prisma\engines\query-engine-windows.exe)
Migration Engine     : migration-engine-cli e421996c87d5f3c8f7eeadd502d4ad402c89464d (at node_modules\@prisma\engines\migration-engine-windows.exe)
Introspection Engine : introspection-core e421996c87d5f3c8f7eeadd502d4ad402c89464d (at node_modules\@prisma\engines\introspection-engine-windows.exe)
Format Binary        : prisma-fmt e421996c87d5f3c8f7eeadd502d4ad402c89464d (at node_modules\@prisma\engines\prisma-fmt-windows.exe)
Default Engines Hash : e421996c87d5f3c8f7eeadd502d4ad402c89464d
Studio               : 0.371.0

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:9
  • Comments:29 (12 by maintainers)

github_iconTop GitHub Comments

16reactions
richin13commented, Feb 4, 2022

I tried using --create-only and ignoring the reset warning hoping it would not reset my DB until I applied the migration on a separate step but instead it wiped my data. Here are the reproduction steps:

  1. I had an existing local development database, generated by a different framework.
  2. I ran prisma db pull to generate a schema.prisma file based on the existing db structure. At this point I have no prisma/migrations/ folder.
  3. I ran prisma migrate dev --name initial-migration --create-only to generate an initial migration based on the existing schema of my DB. I received the warning that, even though I specified --create-only my DB still needs to be reset. I approved it and I ended up with a brand new migration file (just as expected by using prisma migrate) but with an empty local development database (to me, unexpected given that I specified --create-only)

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

I received the above error upon running prisma migrate dev --name initial-migration --create-only

8reactions
NaveenKJammulacommented, Mar 3, 2022

can confirm the issue still exists. prisma migrate dev --create-only should never reset the data. unless we specifically apply it manually.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Prisma Migrate | Database, Schema, SQL Migration Tool
Prisma Migrate is a database migration tool available via the Prisma CLI that integrates with Prisma schema for data modeling.
Read more >
Command Line Interface | RedwoodJS Docs
Appends a DataMigration model to schema.prisma for tracking which data migrations have already run. Creates a DB migration using yarn redwood prisma migrate...
Read more >
Schema Migrations and Patches - Marten DB
All of the schema migration functionality is surfaced through Marten's ... Will *never* drop // any existing objects, so no data loss opts....
Read more >
Detecting Database Drift during Flyway Database Development
Flyway will migrate a database between versions, tracking its version number in a schema history table, but it has no way to prevent...
Read more >
CUBA Studio User Guide
Scaffolding of data model, database schema and CRUD UI. ... now allows developer to drag-and-drop components from the palette to the source ...
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