[Django]-Django 1.9: Field clashes with the field of non-existing field in parent model

31๐Ÿ‘

โœ…

I think that you shouldnโ€™t use name certifier for that foreign key relation because class Profile actually has certifier, admin and designer fields(although by descriptor) according to docs and in that case names actually would clash.

from django.contrib.auth.models import User

c = Certifier.objects.create(
    type='admin',
    user=User.objects.latest('date_joined'),
)

p = c.profile_ptr
print(p.certifier) #username (admin)

Change to something like certifier_field = models.ForeignKey(Certifier)

As it was pointed out in comments, you could rename the models to CertifierProfile, AdminProfile etc to avoid the clash.

Or you could also silence the check by adding SILENCED_SYSTEM_CHECKS = ['models.E006'] to your settings, but this is not a good approach.

๐Ÿ‘คAlex Polekha

30๐Ÿ‘

You can specify Profile is an abstract class. This will stop the check from being confused with your parent fields.

class Meta:
    abstract = True
๐Ÿ‘คmrcai

Leave a comment