Multiple table inheritance subclass with an additional OneToOneField relationship to the parent class
I have a model which in essence boils down to this:
class Person(models.Model): name = models.TextField()
class MarriedMan(Person): wife = models.OneToOneField(Person, on_delete=models.CASCADE, related_name='husband')
But when I try to generate the migration, I get the following error:
django.core.exceptions.ImproperlyConfigured: Add parent_link=True to webapp.MarriedMan.wife.
It looks like Django is promoting the wife OneToOneField to be the parent_link relationship. But that's not what I'm trying to do. I want MarriedMan to have the default implicit OneToOneField for its parent class Person record, plus an extra OneToOneField for its wife.
As far as I was able to understand from the docs, the way to specify that this is not my intention is by not passing parent_link=True.
If you want to control the name of the attribute linking back to the parent, you can create your own OneToOneField and set parent_link=True to indicate that your field is the link back to the parent class.
As a workaround I could manually specify the parent_link relationship in addition to the wife field, but that doesn't seem like the correct solution.