[Django] #36185: manage.py migrate --check --prune actually prunes, which is surprising

15 views
Skip to first unread message

Django

unread,
Feb 12, 2025, 9:45:53 AM2/12/25
to django-...@googlegroups.com
#36185: manage.py migrate --check --prune actually prunes, which is surprising
----------------------------+--------------------------------------
Reporter: Ari Pollak | Type: Bug
Status: new | Component: Migrations
Version: 5.1 | Severity: Normal
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------+--------------------------------------
I ran "manage.py migrate --check --prune app" in a Django 5.1.4 app. Based
on the description of --check, I expected this to not delete any
migrations from the database, but just tell me which ones would be
deleted, like a dry run. But it did delete outdated migrations from the
django_migrations table.

To avoid surprising destructive behavior in the future, I think "migrate
--check --prune" should either not be allowed to run with those combined
options, or should just report which migrations would be pruned and not
actually prune them.
--
Ticket URL: <https://code.djangoproject.com/ticket/36185>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Feb 12, 2025, 10:13:55 AM2/12/25
to django-...@googlegroups.com
#36185: manage.py migrate --check --prune actually prunes, which is surprising
-----------------------------+--------------------------------------
Reporter: Ari Pollak | Owner: (none)
Type: New feature | Status: closed
Component: Migrations | Version: 5.1
Severity: Normal | Resolution: wontfix
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------+--------------------------------------
Changes (by Natalia Bidart):

* resolution: => wontfix
* status: new => closed
* type: Bug => New feature

Comment:

Hello Ari Pollak, thank you for this ticket. I can see the source of
confusion, but I’d like to clarify that `--check is not a `dry-run`-like
option. As described in the help output:
{{{
$ python -Wall manage.py migrate --help

Updates database schema. Manages both apps with migrations and those
without.

[...]
options:
--check Exits with a non-zero status if unapplied
migrations exist and does not actually apply
migrations.
--prune Delete nonexistent migrations from the
django_migrations table.
}}}

The `--check` and `--prune` options operate independently and are
unrelated. `--check` deals with migrations that exist on disk but have not
been applied to the database, while `--prune` does the opposite, removes
migration records from the database that no longer have corresponding
migration files.

Given this, I don’t see a strong reason to prevent these options from
being used together. If the concern is about unintended deletion, perhaps
what this ticket is really suggesting is a `--dry-run` mode for `--prune`?
--
Ticket URL: <https://code.djangoproject.com/ticket/36185#comment:1>

Django

unread,
Mar 3, 2025, 11:01:45 AM3/3/25
to django-...@googlegroups.com
#36185: manage.py migrate --check --prune actually prunes, which is surprising
-----------------------------+--------------------------------------
Reporter: Ari Pollak | Owner: (none)
Type: New feature | Status: closed
Component: Migrations | Version: 5.1
Severity: Normal | Resolution: wontfix
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------+--------------------------------------
Comment (by Adam Johnson):

Since it doesn’t make sense to use the options together, I would prefer to
make them mutually exclusive than wontfix this ticket.
--
Ticket URL: <https://code.djangoproject.com/ticket/36185#comment:2>

Django

unread,
Mar 3, 2025, 11:38:51 AM3/3/25
to django-...@googlegroups.com
#36185: manage.py migrate --check --prune actually prunes, which is surprising
-----------------------------+--------------------------------------
Reporter: Ari Pollak | Owner: (none)
Type: New feature | Status: closed
Component: Migrations | Version: 5.1
Severity: Normal | Resolution: wontfix
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------+--------------------------------------
Comment (by Natalia Bidart):

Replying to [comment:2 Adam Johnson]:
> Since it doesn’t make sense to use the options together

Could you elaborate why? I do think it makes sense in some cases, such as
CI and cleanup jobs...
--
Ticket URL: <https://code.djangoproject.com/ticket/36185#comment:3>
Reply all
Reply to author
Forward
0 new messages