Hi everyone.
Recently I’ve decided to switch some models to multi-table inheritance relation. Some models having no FK / M2M relations already swapped and now I’m trying to find out an easy way to do the same for the models linked with ForeignKey.
As I know concrete inheritance enforce models reffering to parent FK
rather having its own. So whenever last phase of migration applied (setting parent model as class inherited from) on existing model its id
replaced with parent_ptr
field and rest of the models refering to this model through FK
relation loosing that link.
Let’s imagine I have a models:
class Member(models.Model):
pass
class Person_A(models.Model):
member_ptr = OneToOneField(parent_link=True, null=True, blank=True)
class Person_B(models.Model):
member_ptr = OneToOneField(parent_link=True, null=True, blank=True)
class Group(models.Model):
person_a = models.ForeingKey(Person_A)
person_b = models.ForeignKey(Person_B)
In this case Person_A
and Person_B
still have their id
and Group
relations are ok. However when I remove member_ptr
and replacing models.Model
with parent class Member
concrete inheritance enforced but primary key will be changed what causes all FK links to fail.
I have some ideas how to preserve data adding some temporary fields to Group
with FK link to Member
model and make few more steps to transfer data but it fills like I’m missing some easier way.
Would appreciate any ideas.
Just to clear some questions : All Member
instances required to link with Person_A
and Person_B
already created and populated with required data.