Inheritance models from Django 1.8.2 to Django 1.11

59 views
Skip to first unread message

Dmitriy Yusupov

unread,
Apr 10, 2017, 5:57:28 PM4/10/17
to Django users

Hello, I have the task of convert the project from django version 1.8.2 to version 1.11. Faced a problem with which I can not cope. That model of tables, which worked excellently in 1.8.2, stopped working in version 1.11, and falls out with an error:


    core.CarModel.manufacture: (models.E006) The field 'manufacture' clashes with the field 'manufacture' from model 'core.page'.


Apparently this is due to the inheritance of models, since the project is old I can not fundamentally change the scheme of tables, please tell me how to get out of this situation.

Thank you in advance for your help.


I have reproduced the scheme of models, which works fine on 1.8.2 and stops working on 1.11:



    # -*- coding:utf-8 -*-

    from django.db import models

    from django.contrib.contenttypes.models import ContentType



    class InheritanceCastModel(models.Model):


        real_type = models.ForeignKey(ContentType, editable=False)


        def save(self, *args, **kwargs):

            if not self.id:

                self.real_type = self._get_real_type()

            super(InheritanceCastModel, self).save(*args, **kwargs)


        def _get_real_type(self):

            return ContentType.objects.get_for_model(type(self))


        def cast(self):

            return self.real_type.get_object_for_this_type(pk=self.pk)


        class Meta:

            abstract = True



    class Page(InheritanceCastModel):

        title = models.CharField(max_length=512, verbose_name=u'Title', blank=True)



    class Manufacture(Page):

        ru_title = models.CharField(max_length=128, verbose_name=u'RU Title')



    class CarModel(Page):

        manufacture = models.ForeignKey(Manufacture, verbose_name=u'Manufacture')

        ru_title = models.CharField(max_length=64, verbose_name=u'RU Title')



Camilo Torres

unread,
Apr 10, 2017, 6:44:03 PM4/10/17
to Django users
Hi,
May be you can define your field usind "db_column":

manufact = models.ForeignKey(Manufacture, verbose_name=u'Manufacture', db_column='manufacture')

https://docs.djangoproject.com/en/1.11/ref/models/fields/#db-column

Reply all
Reply to author
Forward
0 new messages