I've come across the following scenario where I expected Django to give an
error but it didn't not.
Assume we have 4 migrations for an app, and migration 1 through 3 are
applied.
{{{
# Content of Postgres DB
32 | app_name | 0001_initial
33 | app_name | 0002_migration2
34 | app_name | 0003_migration3
}}}
All migrations except 0001_initial.py were deleted including the folder
pycache. We then run makemigrations
{{{
# Contents of migration folder after makemigrations was ran.
0001_initial.py 0002_name.py __init__.py __pycache__
# Run makemigrations
No Changes Detected
# Output of showmigrations
app_name
[X] 0001_initial
[X] 0002_name
}}}
Contents of Postgres django_migrations, however, remain unchanged still
with an entry for a third migration. I expected an error in one of the
following commands but received none: makemigrations, migrate,
showmigrations.
Also, migrate --fake app_name 0002_name does not lead to the deletion of
0003_migration3 entry in django_migrations
--
Ticket URL: <https://code.djangoproject.com/ticket/28785>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* type: Uncategorized => New feature
* stage: Unreviewed => Accepted
Comment:
Agreed that a warning or system check for this situation would be nice.
However, the docs currently suggest a way to turn a squashed migration
into a normal migration, and it looks like any database that has had this
done will then fail the system check. So, we would need:
* A way to turn squashed migrations into normal migrations in the future
that does not cause the system check to fail,
* A solution for old databases to "reset" the system check, or we can just
recommend people add it to `SILENCED_SYSTEM_CHECKS` (which would be a bit
of a shame)
At the least, there might be a good place in the documentation to add a
warning that migration files should not be removed.
--
Ticket URL: <https://code.djangoproject.com/ticket/28785#comment:1>
* status: new => assigned
* owner: nobody => Sonu kumar
--
Ticket URL: <https://code.djangoproject.com/ticket/28785#comment:2>
* needs_better_patch: 0 => 1
* has_patch: 0 => 1
Comment:
A [https://github.com/django/django/pull/9339 PR] adds a check to
makemigrations. It still needs some improvement.
--
Ticket URL: <https://code.djangoproject.com/ticket/28785#comment:3>
* owner: Sonu kumar => Manav Agarwal
--
Ticket URL: <https://code.djangoproject.com/ticket/28785#comment:4>
* needs_better_patch: 1 => 0
--
Ticket URL: <https://code.djangoproject.com/ticket/28785#comment:5>
* needs_better_patch: 0 => 1
* needs_tests: 0 => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/28785#comment:6>
* owner: Manav Agarwal => uzaxirr
--
Ticket URL: <https://code.djangoproject.com/ticket/28785#comment:7>
* owner: Uzair Ali => Abhinav Yadav
--
Ticket URL: <https://code.djangoproject.com/ticket/28785#comment:8>
Comment (by Adam Johnson):
#26760 added the `--prune` option to `migrate`, to clear up stale entries
from `django_migrations`. Perhaps we no longer need to add a warning now
there's this option.
--
Ticket URL: <https://code.djangoproject.com/ticket/28785#comment:9>
* status: assigned => closed
* resolution: => wontfix
Comment:
Agreed, good spot Adam.
Let's mark as wontfix given the `--prune` option, and the difficulty so
far in providing an appropriate patch. (If future-someone wants to re-open
with a PR for whatever is considered missing then that would be OK.)
--
Ticket URL: <https://code.djangoproject.com/ticket/28785#comment:10>