#32330: Inheritance for already existing models will throw an exception
--------------------------------------------+------------------------
               Reporter:  Vadim Fabrichnov  |          Owner:  nobody
                   Type:  Bug               |         Status:  new
              Component:  Migrations        |        Version:  3.1
               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                 |
--------------------------------------------+------------------------
 **Steps to reproduce:**

 1. Create 2 models that have models.Model in bases and make migrations:

 {{{
 class A(models.Model):
     pass
 class B(models.Model):
     pass
 }}}

 2. Try to apply multi-table inheritance to one of them:
 {{{
 class B(A):
     pass
 }}}

 **Results:**

 You will get an exception:

 {{{
 django.core.exceptions.FieldError: Local field 'id' in class 'B' clashes
 with field of the same name from base class 'A'.
 }}}
 btw, if you have more than one model in bases, you will get the error
 also, even if it's a freshly created model.

 I can see 2 possible solutions:

 1. Rename ID field, change it to models.OneToOne with primary_key and make
 sure the user will prepopulate that field somehow.
 2. Just raise the exception and ask the user to write migration manually.


 This ticket is kinda related to
 https://code.djangoproject.com/ticket/23521 that I already fixed. If it's
 worth working on, I can fix this ticket also.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/32330>
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/050.53cc89af141232823e263af4341e1f22%40djangoproject.com.

Reply via email to