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 
> <https://docs.djangoproject.com/en/dev/ref/models/fields/#django.db.models.OneToOneField>
>  and 
> set parent_link=True 
> <https://docs.djangoproject.com/en/dev/ref/models/fields/#django.db.models.OneToOneField.parent_link>
>  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.

Am I missing something?

Thanks.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/fd82f238-b141-4283-8d14-20969a9855b9%40googlegroups.com.

Reply via email to