﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
36146	Double-squashed migration is omitted from forward migration plan after migrating backward	Jacob Walls	Georgi Yanchev	"Start with this `models.py` and generate three simple migrations:
{{{#!python
from django.db import models

class A(models.Model):
    foo = models.BooleanField()
}}}

{{{
./manage.py makemigrations 
}}}

{{{#!python
from django.db import models

class A(models.Model):
    foo = models.BooleanField(default=True)
}}}

{{{
./manage.py makemigrations 
}}}

{{{#!python
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
}}}
"	Bug	closed	Migrations	dev	Release blocker	fixed		Georgi Yanchev	Ready for checkin	1	0	0	0	0	0
