There is an old code with two models shown as below:
class Watermelon(models.Model):
id = models.AutoField(primary_key=True)
name = models.CharField(max_length=64, default='Unnamed Watermelon')
is_allegic = models.BooleanField(default=False)
use_by = models.DateTimeField()
seedless = models.BooleanField(default=False)
class Pear(models.Model):
id = models.AutoField(primary_key=True)
name = models.CharField(max_length=64, default='Unnamed Pear')
is_allegic = models.BooleanField(default=False)
use_by = models.DateTimeField()
round_shape = models.BooleanField(default=False)
Now I need a generic fruit search related functions so I am trying to use model inheritance without disturbing the original ID numbers from the old data:
class Fruit(models.Model):
name = models.CharField(max_length=64, default='Unnamed Fruit')
is_allegic = models.BooleanField(default=False)
use_by = models.DateTimeField()
class Watermelon(Fruit):
id = models.AutoField(primary_key=True)
seedless = models.BooleanField(default=False)
class Pear(Fruit):
id = models.AutoField(primary_key=True)
round_shape = models.BooleanField(default=False)
And this causes the conflict for the field 'id', as django doesn't allow to override fields in the subclass models.
I also tried to add a different AutoField 'base_id' in Fruit model, since the ID in the parent model is not going to be used at all. But then I am getting "django.db.utils.ProgrammingError: relation "Fruit" already exists" error when trying to run south makemigrations.
I understand that renumbering all IDs and share them with all subclass models can solve the problem, but I try to avoid this method because those IDs are already referenced by other tables and also used by other systems.
Any advice will be appreciated.