`migrate dev --create-only` with empty schema but existing database schema detects drift and warns about deleting all data
See original GitHub issueBug 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:
- Created 2 years ago
- Reactions:9
- Comments:29 (12 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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:prisma db pull
to generate aschema.prisma
file based on the existing db structure. At this point I have noprisma/migrations/
folder.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 usingprisma migrate
) but with an empty local development database (to me, unexpected given that I specified--create-only
)I received the above error upon running
prisma migrate dev --name initial-migration --create-only
can confirm the issue still exists.
prisma migrate dev --create-only
should never reset the data. unless we specifically apply it manually.