Opened 10 months ago

Last modified 12 days ago

#36141 closed Bug

After double squashing migrate command fails with InconsistentMigrationHistory — at Version 7

Reported by: Jacob Walls Owned by:
Component: Migrations Version: 6.0
Severity: Release blocker Keywords:
Cc: Georgi Yanchev Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Natalia Bidart)

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.

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.

Change History (7)

comment:1 by Sarah Boyce, 10 months ago

Cc: Georgi Yanchev added

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 docs?

comment:2 by Sarah Boyce, 10 months ago

Resolution: needsinfo
Status: newclosed

Closing as "needsinfo", pending feedback from Jacob in case there's something I'm missing or a docs change might help.

comment:3 by Jacob Walls, 10 months ago

Resolution: needsinfoinvalid
Severity: Release blockerNormal

Ah right thanks. Was trying to distill a more complicated failure and went a little too far. Docs read fine!

comment:4 by Georgi Yanchev, 2 weeks ago

Has patch: set
Resolution: invalid
Status: closednew

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.

comment:5 by Jacob Walls, 2 weeks ago

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.

comment:6 by Jacob Walls, 2 weeks ago

Severity: NormalRelease blocker
Version: dev6.0

comment:7 by Natalia Bidart, 13 days ago

Description: modified (diff)
Note: See TracTickets for help on using tickets.
Back to Top