#27764: Running migration that deletes child model (in multi-table inheritance)
backwards results in an error
------------------------------------------------+------------------------
               Reporter:  Alexandru Mărășteanu  |          Owner:  nobody
                   Type:  Bug                   |         Status:  new
              Component:  Migrations            |        Version:  1.10
               Severity:  Normal                |       Keywords:
           Triage Stage:  Unreviewed            |      Has patch:  0
    Needs documentation:  0                     |    Needs tests:  0
Patch needs improvement:  0                     |  Easy pickings:  0
                  UI/UX:  0                     |
------------------------------------------------+------------------------
 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.

--
Ticket URL: <https://code.djangoproject.com/ticket/27764>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/049.c8ab6aac4ffa9421c7095a7e838a9c47%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to