Migrate: `--create-only` flag applies non-applied migrations
See original GitHub issueBug description
The --create-only flag does not seem to work correctly. We (at work) were working on a feature branch, consisting of some migration files. When the first migration file was created with the --create-only flag it wasn’t directly applied, like expected. But when we created another migration with the same flag the previous migration got applied, because it wasn’t yet applied. This was not the expected behavior.
Context: https://github.com/prisma/prisma/issues/5553#issuecomment-775974318
How to reproduce
Steps to reproduce the behavior:
- Create a migration file with the
--create-onlyflag applied - Create another migration file with the
--create-onlyflag applied - See that the previous, unapplied migration got applied
Expected behavior
No migration file applies.
Possible solutions
See https://github.com/prisma/prisma/issues/5553#issuecomment-775909044
Environment & setup
- OS: Mac OS
- Database: Aurora MySQL
- Node.js version: v12.18.4
- Prisma version: 2.16.1
Environment variables loaded from .env
prisma : 2.16.1
@prisma/client : 2.16.1
Current platform : darwin
Query Engine : query-engine 8b74ad57aaf2cc6c155f382a18a8e3ba95aceb03 (at node_modules/@prisma/engines/query-engine-darwin)
Migration Engine : migration-engine-cli 8b74ad57aaf2cc6c155f382a18a8e3ba95aceb03 (at node_modules/@prisma/engines/migration-engine-darwin)
Introspection Engine : introspection-core 8b74ad57aaf2cc6c155f382a18a8e3ba95aceb03 (at node_modules/@prisma/engines/introspection-engine-darwin)
Format Binary : prisma-fmt 8b74ad57aaf2cc6c155f382a18a8e3ba95aceb03 (at node_modules/@prisma/engines/prisma-fmt-darwin)
Studio : 0.346.0
Issue Analytics
- State:
- Created 3 years ago
- Comments:13 (7 by maintainers)
Top Results From Across the Web
Migrations - Django documentation
Migrations ¶. Migrations are Django's way of propagating changes you make to your models (adding a field, deleting a model, etc.) into your...
Read more >django-admin migrate [app_label] [migration_name] - Fig.io
Make sure that the current database schema matches your initial migration before using this flag. Django will only check for an existing table...
Read more >Django "You have unapplied migrations". Which ones?
A minor modification on Kevin's answer using grep, to only show unapplied migrations: Django 1.7: python manage.py migrate --list | grep -v '\[X\]'....
Read more >Prisma Migrate | Database, Schema, SQL Migration Tool
Does not apply for MongoDB. Instead of migrate dev and related commands, use db push for MongoDB. Prisma Migrate is an imperative database...
Read more >Overcome Common Migration Pitfalls - Create a Web ...
This technique only works if the migrations don't affect the same field on the same model. If they do, your best course of...
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 Free
Top 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

Totally agree on that.
Our workflow is a bit different. In our case we are working with the live/production database since we are working serverless and do not have a locally running database. Means that we are in any case communicating with the live database to ensure that we are building upon the correct, live deployed state of the current database.
The argument that
--create-onlyshould apply migrations is misleading and wrong. I understand why it wants to apply the previous migration, since it needs a reference on what the next migration should build upon (I think). But when it says, that it only wants to create a migration but not apply it, why does it apply it in the first place?As I suggested (https://github.com/prisma/prisma/issues/5553#issuecomment-775909044) there may be three, or more, possible solutions to this problem.
I totally agree, just hit this myself and it was 100% non intuitive this would happen. I absolutely expected it to just create a new migration for me to review:
This is pretty dangerous. At the very least, we should prompt for confirmation if there are older non applied migrations that will be applied.