[Answered ]-Conflict in django models . How to debug?


The problem is that when you create a ForeignKey linking to another model, there is a backward relationship automatically created on that to model. In your case on permissions.Permission the ForeignKey to ContentType means there will be a manager added to ContentType called permission_set that will allow access back to permissions.Permission objects that link to it.

The reason why it does not work is that it’s ambiguous whether the backward relationship manager permission_set should refer to your permissions.Permission model, or the built-in auth.Permission model. (Both have a ForeignKey to ContentType, and so a backward relationship manager is created for both.)

To resolve this problem, you must use the related_name parameter to ForeignKey. This allows your to override the default FOO_set name, with your own. e.g.:

class Permission(models.Model):
    user = models.ForeignKey(User)
    table = models.ForeignKey(ContentType, related_name='custom_permission_set') 
    permi = models.IntegerField()

Leave a comment