This is the error I get .
auth.permission: Accessor for field 'content_type' clashes with related field 'ContentType.permission_set'. Add a related_name argument to the definition for 'content_type'.
permissions.permission: Accessor for field 'table' clashes with related field 'ContentType.permission_set'. Add a related_name argument to the definition for 'table'.
This is my model .
from django.contrib.gis.db import models
from django.contrib.auth.models import User
from django.contrib.contenttypes.models import ContentType
from maps.models import Sdr_Layer
class Permission(models.Model):
user = models.ForeignKey(User)
table = models.ForeignKey(ContentType)
permi = models.IntegerField()
Can someone explain to me what the error means and how to remove it ?
The problem is that when you create a
ForeignKeylinking to another model, there is a backward relationship automatically created on that to model. In your case onpermissions.PermissiontheForeignKeytoContentTypemeans there will be a manager added toContentTypecalledpermission_setthat will allow access back topermissions.Permissionobjects that link to it.The reason why it does not work is that it’s ambiguous whether the backward relationship manager
permission_setshould refer to yourpermissions.Permissionmodel, or the built-inauth.Permissionmodel. (Both have aForeignKeytoContentType, and so a backward relationship manager is created for both.)To resolve this problem, you must use the
related_nameparameter toForeignKey. This allows your to override the defaultFOO_setname, with your own. e.g.: