﻿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
27764	Running migration that deletes child model (in multi-table inheritance) backwards results in an error	Alexandru Mărășteanu	nobody	"1. Create two models where one of them inherits the other:
{{{
class Foo(models.Model):
    test = models.CharField(max_length=256)


class Bar(Foo):
    pass
}}}

2. Generate and run migrations.

`migrations/0001_initial.py` is:
{{{
...
    operations = [
        migrations.CreateModel(
            name='Foo',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('test', models.CharField(max_length=256)),
            ],
        ),
        migrations.CreateModel(
            name='Bar',
            fields=[
                ('foo_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='foo.Foo')),
            ],
            bases=('foo.foo',),
        ),
    ]
...
}}}

3. Delete the child model (`Bar`)

4. Generate and run migrations again.

`migrations/0002_auto_20170123_1212.py` is:
{{{
...
        migrations.RemoveField(
            model_name='bar',
            name='foo_ptr',
        ),
        migrations.DeleteModel(
            name='Bar',
        ),
...
}}}

5. Run migrations backwards (i.e. `python migrate APP zero`)
{{{
django.db.utils.ProgrammingError: column ""foo_ptr_id"" of relation ""foo_bar"" already exists
}}}

Verified with Django (1.9.6, 1.9.12 and 1.10.5) and psycopg2 (2.5.2) on macOS 10.12.2 with Python 2.7.12, PostgreSQL 9.5.4."	Bug	new	Migrations	1.10	Normal				Unreviewed	0	0	0	0	0	0
