To reproduce my problem, please download the following files from
[https://github.com/lino-framework/book/tree/master/docs/tested/diamond
this directory] of my repository:
- [https://github.com/lino-
framework/book/blob/master/docs/tested/diamond/main/models.py
main/models.py]
- `main/__init__.py`
- `manage.py`
- `settings.py`
and then run:
{{{
$ python manage.py check
}}}
The output is:
{{{
SystemCheckError: System check identified some issues:
ERRORS:
main.PizzeriaBar: (models.E005) The field 'restaurant_ptr' from parent
model 'main.bar' clashes with the field 'restaurant_ptr' from parent model
'main.pizzeria'.
}}}
The failure works in Django versions 1.11.2, 1.10.7, 1.9.13 (and maybe
earlier as well).
I could not find any relevant difference between my code and the example
in the documentation.
Any hints?
--
Ticket URL: <https://code.djangoproject.com/ticket/28332>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* type: Uncategorized => Bug
* component: Uncategorized => Documentation
* stage: Unreviewed => Accepted
Comment:
It looks like the example in the documentation (added in #22442) never
worked. I tested back to Django 1.7 and the check error is the same. If it
cannot be fixed, perhaps it should be removed.
--
Ticket URL: <https://code.djangoproject.com/ticket/28332#comment:1>
* owner: nobody => Jeremy Satterfield
* status: new => assigned
* has_patch: 0 => 1
Comment:
The `PizzeriaBar` model is inheriting the `restaurant_ptr` field from both
`Pizzeria` and `Bar`, so you need to specify the parent link field on at
least one of them, per
https://docs.djangoproject.com/en/dev/topics/db/models/#specifying-the-
parent-link-field. This gets a little complicated if you are creating this
child model and overriding these field names at a later date than the
parent since you are changing the field name, it is going to require using
the `db_column` arg on the field or more complex migrations.
This seems to me to have a lot of caveats to be provided as an example in
the docs; however, here is a PR that updates the existing example to be
working.
--
Ticket URL: <https://code.djangoproject.com/ticket/28332#comment:2>
Comment (by Luc Saffre):
I confirm that this fixes the problem. Yes, diamond inheritance has more
problems than this (see [http://luc.lino-framework.org/blog/2017/0823.html
my blog] for an example) and I currently avoid it in my projects. But
still it is a feature for Django and I recommend to not remove if from the
docs (but to rather write more about it).
--
Ticket URL: <https://code.djangoproject.com/ticket/28332#comment:3>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"473ab4610ef90be05f09127aa37cd20bcda5875e" 473ab461]:
{{{
#!CommitTicketReference repository=""
revision="473ab4610ef90be05f09127aa37cd20bcda5875e"
Fixed #28332 -- Fixed diamond inheritence example in docs.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/28332#comment:4>
Comment (by Tim Graham <timograham@…>):
In [changeset:"e921e983876b62f5b8f405e0b8afcdcc1f53d8bb" e921e98]:
{{{
#!CommitTicketReference repository=""
revision="e921e983876b62f5b8f405e0b8afcdcc1f53d8bb"
[1.11.x] Fixed #28332 -- Fixed diamond inheritence example in docs.
Backport of 473ab4610ef90be05f09127aa37cd20bcda5875e from master
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/28332#comment:5>