﻿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
32205	sqlmigrate crashes after removing squashed migrations.	老广	nobody	"After upgrade django 2.2 to 3.1, If migrations was squashed, then sqlmigrate cause error. If back to 2.2, error lost.

The migrate file error refer is in squash file.


**Error stack**

{{{
  File ""/Users/guang/vm/py/py36/lib/python3.6/site-packages/django/core/management/commands/sqlmigrate.py"", line 37, in handle
    loader = MigrationLoader(connection, replace_migrations=False)
  File ""/Users/guang/vm/py/py36/lib/python3.6/site-packages/django/db/migrations/loader.py"", line 53, in __init__
    self.build_graph()
  File ""/Users/guang/vm/py/py36/lib/python3.6/site-packages/django/db/migrations/loader.py"", line 255, in build_graph
    self.graph.validate_consistency()
  File ""/Users/guang/vm/py/py36/lib/python3.6/site-packages/django/db/migrations/graph.py"", line 195, in validate_consistency
    [n.raise_error() for n in self.node_map.values() if isinstance(n, DummyNode)]
  File ""/Users/guang/vm/py/py36/lib/python3.6/site-packages/django/db/migrations/graph.py"", line 195, in <listcomp>
    [n.raise_error() for n in self.node_map.values() if isinstance(n, DummyNode)]
  File ""/Users/guang/vm/py/py36/lib/python3.6/site-packages/django/db/migrations/graph.py"", line 58, in raise_error
    raise NodeNotFoundError(self.error_message, self.key, origin=self.origin)
django.db.migrations.exceptions.NodeNotFoundError: Migration assets.0020_auto_20180816_1652 dependencies reference nonexistent parent node ('assets', '0019_auto_20180816_1320')
}}}
 

**Migrations**

source code: https://github.com/jumpserver/jumpserver/blob/master/apps/assets/migrations/0020_auto_20180816_1652.py

{{{
# Generated by Django 2.0.7 on 2018-08-16 08:52

from django.db import migrations, models


class Migration(migrations.Migration):

    dependencies = [
        ('assets', '0019_auto_20180816_1320'),
    ]

    operations = [
        migrations.AlterField(
            model_name='adminuser',
            name='org_id',
            field=models.CharField(blank=True, db_index=True, default='', max_length=36, verbose_name='Organization'),
        ),
}}}


The squash migrations:

source code: https://github.com/jumpserver/jumpserver/blob/master/apps/assets/migrations/0010_auto_20180307_1749_squashed_0019_auto_20180816_1320.py

{{{
class Migration(migrations.Migration):

    replaces = [('assets', '0010_auto_20180307_1749'), ('assets', '0011_auto_20180326_0957'), ('assets', '0012_auto_20180404_1302'), ('assets', '0013_auto_20180411_1135'), ('assets', '0014_auto_20180427_1245'), ('assets', '0015_auto_20180510_1235'), ('assets', '0016_auto_20180511_1203'), ('assets', '0017_auto_20180702_1415'), ('assets', '0018_auto_20180807_1116'), ('assets', '0019_auto_20180816_1320')]

    dependencies = [
        ('assets', '0009_auto_20180307_1212'),
    ]

}}}
"	Bug	closed	Database layer (models, ORM)	3.1	Normal	invalid	sqlmigrate	ibuler@…	Accepted	0	0	0	0	0	0
