Opened 37 hours ago

Last modified 13 hours ago

#36146 new Bug

Double-squashed migration is omitted from forward migration plan after migrating backward

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

Description

Start with this models.py and generate three simple migrations:

from django.db import models

class A(models.Model):
    foo = models.BooleanField()
./manage.py makemigrations 
from django.db import models

class A(models.Model):
    foo = models.BooleanField(default=True)
./manage.py makemigrations 
from django.db import models

class A(models.Model):
    foo = models.BooleanField(default=False)
./manage.py makemigrations 

Migrate.
Squash, migrate, double-squash, migrate.
Migrate back to zero.

./manage.py migrate
./manage.py squashmigrations new 0001 0002
./manage.py migrate
./manage.py squashmigrations new 0001_initial_squashed 0003
./manage.py migrate
./manage.py migrate new zero

Now notice the forward plan is missing a migration:

./manage.py migrate
Operations to perform:
  Apply all migrations: new
Running migrations:
  Applying new.0003_alter_a_foo... OK

And reverse migrate fails (failure would have been evident in the last step if it hadn't been an SQL noop):

./manage.py migrate new zero
Operations to perform:
  Unapply all migrations: new
Running migrations:
  Rendering model states... DONE
  Unapplying new.0001_initial_squashed_0002_alter_a_foo_squashed_0003_alter_a_foo...Traceback (most recent call last):
  File "/Users/jwalls/django/django/db/backends/utils.py", line 103, in _execute
    return self.cursor.execute(sql)
           ~~~~~~~~~~~~~~~~~~~^^^^^
psycopg2.errors.UndefinedTable: table "new_a" does not exist

Change History (4)

comment:1 by Jacob Walls, 37 hours ago

Summary: Double-squashed migration is omitted from migration planDouble-squashed migration is omitted from forward migration plan after migrating backward

I assume that the first squashed migration is not being unrecorded along with the second squashed migration when migrating to zero.

comment:2 by Sarah Boyce, 34 hours ago

Cc: Georgi Yanchev added
Triage Stage: UnreviewedAccepted

Thank you!
Replicated, regression in 64b1ac7292c72d3551b2ad70b2a78c8fe4af3249 (refs #24529).

comment:3 by Ayush Khatri , 14 hours ago

Owner: set to Ayush Khatri
Status: newassigned

comment:4 by Ayush Khatri , 13 hours ago

Owner: Ayush Khatri removed
Status: assignednew
Note: See TracTickets for help on using tickets.
Back to Top