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.
* owner: nobody => derekniess
* status: new => assigned
--
Ticket URL: <https://code.djangoproject.com/ticket/32330#comment:1>
* owner: derekniess => (none)
* status: assigned => new
--
Ticket URL: <https://code.djangoproject.com/ticket/32330#comment:2>
* status: new => closed
* resolution: => worksforme
Comment:
Replying to [ticket:32330 Vadim Fabrichnov]:
> 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'.
> }}}
I cannot reproduce this issue, after changing inheritance
`makemigrations` creates (as expected) two operations:
- `Remove field id from b`
- `Add field a_ptr to b`
> btw, if you have more than one model in bases, you will get the error
also, even if it's a freshly created model.
This is a [https://docs.djangoproject.com/en/3.1/topics/db/models
/#multiple-inheritance documented behavior].
--
Ticket URL: <https://code.djangoproject.com/ticket/32330#comment:1>