Despite what django doc says, multiple inheritance with a common ancestor causes an error(models.E005). I found a tricky solution, but are there any better solutions?

76 views
Skip to first unread message

Hyunsoo Kim

unread,
Jun 13, 2017, 12:58:32 PM6/13/17
to Django users
This doc says multiple inheritance with a common ancestor can do the job.
However, I've experienced an error while making migrations.
Here's the error message.
models.E005: The field '<common-ancestor>_ptr' from parent model '<myapp>.<parent-1>' clashes with the field '<common-ancestor>_ptr' from parent model '<myapp>.<parent-2>'.

After some googling, I fount this stackoverflow Q&A.
This solves the problem by create an explicit different parent_link in parent model to prevent collision.
But it seems redundant to hold two multiple ancestor link in the child model.
Is there any solution with no redundant field?

Melvyn Sopacua

unread,
Jun 14, 2017, 6:12:42 AM6/14/17
to django...@googlegroups.com

On Tuesday 13 June 2017 09:54:03 Hyunsoo Kim wrote:

> This doc

> <https://docs.djangoproject.com/en/1.11/topics/db/models/#multiple-inh

> eritance> says multiple inheritance with a common ancestor can do the

> job. However, I've experienced an error while making migrations.

> Here's the error message.

>

> > models.E005: The field '*<common-ancestor>*_ptr' from parent model '

> > *<myapp>.<parent-1>*' clashes with the field

> > '*<common-ancestor>_*ptr' from parent model '*<myapp>.<parent-2>*'.

>

> After some googling, I fount this stackoverflow Q&A

> This solves the problem by create an explicit different parent_link in

> parent model to prevent collision.

> But it seems redundant to hold two multiple ancestor link in the child

> model.

> Is there any solution with no redundant field?

 

Sorry, but you haven't convinced us you've implemented the common ancestor part properly. It means you have at minimum 4 models in play and none of them can be abstract.

The most common error is to mark the grandparent abstract and this copies the autofield to it's children instead of having a shared parent link.

 

Gotta say though, that the docs are sparse.

--

Melvyn Sopacua

Hyunsoo Kim

unread,
Jun 15, 2017, 9:52:52 AM6/15/17
to Django users
Currently no model is abstract. I can guarantee this because each model is referenced by one or more foreign keys.
I don't think this is my special case problem. The same problem happens when you use the common ancestor model in the django document.
Reply all
Reply to author
Forward
0 new messages