[Django] #36141: After double squashing migrate command fails with InconsistentMigrationHistory

32 views
Skip to first unread message

Django

unread,
Jan 26, 2025, 2:56:04 PM1/26/25
to django-...@googlegroups.com
#36141: After double squashing migrate command fails with
InconsistentMigrationHistory
-----------------------------+-------------------------------------------
Reporter: Jacob Walls | Type: Bug
Status: new | Component: Migrations
Version: dev | Severity: Release blocker
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------+-------------------------------------------
[main/6.0]
Make four migrations, migrate, squash the first two, then squash the first
three: then migrate (or makemigrations --check) fails.

{{{#!shell
manage.py makemigrations myapp --empty
manage.py makemigrations myapp --empty
manage.py makemigrations myapp --empty
manage.py makemigrations myapp --empty
manage.py migrate
manage.py squashmigrations myapp 0001 0002
manage.py squashmigrations myapp 0001_initial_squashed 0003
manage.py migrate
}}}

{{{
django.db.migrations.exceptions.InconsistentMigrationHistory: Migration
myapp.0004_auto_20250126_1339 is applied before its dependency
new.0001_initial_squashed_0002_auto_20250126_1339_squashed_0003_auto_20250126_1339
on database 'default'.
}}}

Other migration commands can be subbed for that last call and still
produce the same error, e.g. `makemigrations --check`, which is likely in
a CI setting.
--
Ticket URL: <https://code.djangoproject.com/ticket/36141>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jan 27, 2025, 2:57:49 AM1/27/25
to django-...@googlegroups.com
#36141: After double squashing migrate command fails with
InconsistentMigrationHistory
---------------------------------+--------------------------------------
Reporter: Jacob Walls | Owner: (none)
Type: Bug | Status: new
Component: Migrations | Version: dev
Severity: Release blocker | Resolution:
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 Sarah Boyce):

* cc: Georgi Yanchev (added)

Comment:

You should run migrate after each squash:

> Once you’ve squashed your migration, you should then commit it alongside
the migrations it replaces and distribute this change to all running
instances of your application, making sure that they run migrate to store
the change in their database.

Do you think this needs to be clearer in the
[https://docs.djangoproject.com/en/dev/topics/migrations/#migration-
squashing docs]?
--
Ticket URL: <https://code.djangoproject.com/ticket/36141#comment:1>

Django

unread,
Jan 27, 2025, 2:59:12 AM1/27/25
to django-...@googlegroups.com
#36141: After double squashing migrate command fails with
InconsistentMigrationHistory
---------------------------------+--------------------------------------
Reporter: Jacob Walls | Owner: (none)
Type: Bug | Status: closed
Component: Migrations | Version: dev
Severity: Release blocker | Resolution: needsinfo
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 Sarah Boyce):

* resolution: => needsinfo
* status: new => closed

Comment:

Closing as "needsinfo", pending feedback from Jacob in case there's
something I'm missing or a docs change might help.
--
Ticket URL: <https://code.djangoproject.com/ticket/36141#comment:2>

Django

unread,
Jan 27, 2025, 8:14:56 AM1/27/25
to django-...@googlegroups.com
#36141: After double squashing migrate command fails with
InconsistentMigrationHistory
-----------------------------+--------------------------------------
Reporter: Jacob Walls | Owner: (none)
Type: Bug | Status: closed
Component: Migrations | Version: dev
Severity: Normal | Resolution: invalid
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 Jacob Walls):

* resolution: needsinfo => invalid
* severity: Release blocker => Normal

Comment:

Ah right thanks. Was trying to distill a more complicated failure and went
a little too far. Docs read fine!
--
Ticket URL: <https://code.djangoproject.com/ticket/36141#comment:3>

Django

unread,
Nov 13, 2025, 6:59:16 PM11/13/25
to django-...@googlegroups.com
#36141: After double squashing migrate command fails with
InconsistentMigrationHistory
-----------------------------+--------------------------------------
Reporter: Jacob Walls | Owner: (none)
Type: Bug | Status: new
Component: Migrations | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------+--------------------------------------
Changes (by Georgi Yanchev):

* has_patch: 0 => 1
* resolution: invalid =>
* status: closed => new

Comment:

I think the bug is valid, and we just hit it in our production app.
Running "migrate" after each squash is not always possible, as we can't
track all the deployments in the wild and some customers upgrade very
infrequently.

I've created a patch.
--
Ticket URL: <https://code.djangoproject.com/ticket/36141#comment:4>

Django

unread,
Nov 14, 2025, 11:16:30 AM11/14/25
to django-...@googlegroups.com
#36141: After double squashing migrate command fails with
InconsistentMigrationHistory
-----------------------------+--------------------------------------
Reporter: Jacob Walls | Owner: (none)
Type: Bug | Status: new
Component: Migrations | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------+--------------------------------------
Comment (by Jacob Walls):

Thanks, I agree that reusable apps (e.g. `django.contrib.auth`) don't have
a way of tracking their deployments. Seems reasonable to accept, but I'm
the author so I'll wait for someone else to.
--
Ticket URL: <https://code.djangoproject.com/ticket/36141#comment:5>

Django

unread,
Nov 14, 2025, 2:41:57 PM11/14/25
to django-...@googlegroups.com
#36141: After double squashing migrate command fails with
InconsistentMigrationHistory
---------------------------------+--------------------------------------
Reporter: Jacob Walls | Owner: (none)
Type: Bug | Status: new
Component: Migrations | Version: 6.0
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
---------------------------------+--------------------------------------
Changes (by Jacob Walls):

* severity: Normal => Release blocker
* version: dev => 6.0

--
Ticket URL: <https://code.djangoproject.com/ticket/36141#comment:6>

Django

unread,
Nov 17, 2025, 1:10:52 PM11/17/25
to django-...@googlegroups.com
#36141: After double squashing migrate command fails with
InconsistentMigrationHistory
---------------------------------+--------------------------------------
Reporter: Jacob Walls | Owner: (none)
Type: Bug | Status: new
Component: Migrations | Version: 6.0
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
---------------------------------+--------------------------------------
Description changed by Natalia Bidart:

Old description:

> [main/6.0]
> Make four migrations, migrate, squash the first two, then squash the
> first three: then migrate (or makemigrations --check) fails.
>
> {{{#!shell
> manage.py makemigrations myapp --empty
> manage.py makemigrations myapp --empty
> manage.py makemigrations myapp --empty
> manage.py makemigrations myapp --empty
> manage.py migrate
> manage.py squashmigrations myapp 0001 0002
> manage.py squashmigrations myapp 0001_initial_squashed 0003
> manage.py migrate
> }}}
>
> {{{
> django.db.migrations.exceptions.InconsistentMigrationHistory: Migration
> myapp.0004_auto_20250126_1339 is applied before its dependency
> new.0001_initial_squashed_0002_auto_20250126_1339_squashed_0003_auto_20250126_1339
> on database 'default'.
> }}}
>
> Other migration commands can be subbed for that last call and still
> produce the same error, e.g. `makemigrations --check`, which is likely in
> a CI setting.

New description:

Ticket #24529 implemented the possibility to squash squashed migrations.

To reproduce this issue, make four migrations, migrate, squash the first
two, then squash the first three: then migrate (or makemigrations --check)
fails.

{{{#!shell
manage.py makemigrations myapp --empty
manage.py makemigrations myapp --empty
manage.py makemigrations myapp --empty
manage.py makemigrations myapp --empty
manage.py migrate
manage.py squashmigrations myapp 0001 0002
manage.py squashmigrations myapp 0001_initial_squashed 0003
manage.py migrate
}}}

{{{
django.db.migrations.exceptions.InconsistentMigrationHistory: Migration
myapp.0004_auto_20250126_1339 is applied before its dependency
new.0001_initial_squashed_0002_auto_20250126_1339_squashed_0003_auto_20250126_1339
on database 'default'.
}}}

Other migration commands can be subbed for that last call and still
produce the same error, e.g. `makemigrations --check`, which is likely in
a CI setting.

--
--
Ticket URL: <https://code.djangoproject.com/ticket/36141#comment:7>

Django

unread,
Nov 17, 2025, 1:11:37 PM11/17/25
to django-...@googlegroups.com
#36141: After double squashing migrate command fails with
InconsistentMigrationHistory
---------------------------------+------------------------------------
Reporter: Jacob Walls | Owner: (none)
Type: Bug | Status: new
Component: Migrations | Version: 6.0
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
---------------------------------+------------------------------------
Changes (by Natalia Bidart):

* stage: Unreviewed => Accepted

--
Ticket URL: <https://code.djangoproject.com/ticket/36141#comment:8>

Django

unread,
Nov 17, 2025, 1:50:33 PM11/17/25
to django-...@googlegroups.com
#36141: After double squashing migrate command fails with
InconsistentMigrationHistory
-------------------------------------+-------------------------------------
Reporter: Jacob Walls | Owner: (none)
Type: Bug | Status: new
Component: Migrations | Version: 6.0
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Jacob Walls):

* stage: Accepted => Ready for checkin

--
Ticket URL: <https://code.djangoproject.com/ticket/36141#comment:9>

Django

unread,
Nov 17, 2025, 7:19:41 PM11/17/25
to django-...@googlegroups.com
#36141: After double squashing migrate command fails with
InconsistentMigrationHistory
-------------------------------------+-------------------------------------
Reporter: Jacob Walls | Owner: Georgi
| Yanchev
Type: Bug | Status: assigned
Component: Migrations | Version: 6.0
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Jacob Walls):

* owner: (none) => Georgi Yanchev
* status: new => assigned

--
Ticket URL: <https://code.djangoproject.com/ticket/36141#comment:10>

Django

unread,
Nov 18, 2025, 8:10:37 AM11/18/25
to django-...@googlegroups.com
#36141: After double squashing migrate command fails with
InconsistentMigrationHistory
-------------------------------------+-------------------------------------
Reporter: Jacob Walls | Owner: Georgi
| Yanchev
Type: Bug | Status: closed
Component: Migrations | Version: 6.0
Severity: Release blocker | Resolution: fixed
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by GitHub <noreply@…>):

* resolution: => fixed
* status: assigned => closed

Comment:

In [changeset:"b07298a73a8d444b3618aad8005055bee5ead8cb" b07298a7]:
{{{#!CommitTicketReference repository=""
revision="b07298a73a8d444b3618aad8005055bee5ead8cb"
Fixed #36141 -- Checked for applied replaced migrations recursively.

Regression in 64b1ac7292c72d3551b2ad70b2a78c8fe4af3249.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/36141#comment:11>

Django

unread,
Nov 18, 2025, 8:11:58 AM11/18/25
to django-...@googlegroups.com
#36141: After double squashing migrate command fails with
InconsistentMigrationHistory
-------------------------------------+-------------------------------------
Reporter: Jacob Walls | Owner: Georgi
| Yanchev
Type: Bug | Status: closed
Component: Migrations | Version: 6.0
Severity: Release blocker | Resolution: fixed
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Jacob Walls <jacobtylerwalls@…>):

In [changeset:"569f455b589039d1a123d7c27b6e2fd0d2c795df" 569f455]:
{{{#!CommitTicketReference repository=""
revision="569f455b589039d1a123d7c27b6e2fd0d2c795df"
[6.0.x] Fixed #36141 -- Checked for applied replaced migrations
recursively.

Regression in 64b1ac7292c72d3551b2ad70b2a78c8fe4af3249.
Backport of b07298a73a8d444b3618aad8005055bee5ead8cb from main.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/36141#comment:12>
Reply all
Reply to author
Forward
0 new messages