Django: ManytoManyField model validation error

I get this error when running syncdb

Does not seem to figure out the problem. Please, help.

    Error: One or more models did not validate:
store.business: Reverse query name for field 'logo' clashes with field 'ImageBank.business'. Add a related_name argument to the definition for 'logo'.

Here are my models:

class Business(models.Model):
    business_type = models.ManyToManyField(BusinessType)
    business_service_type = models.ManyToManyField(ServiceType)
    establishment_type = models.ForeignKey(EstablishmentType)
    logo = models.ForeignKey(ImageBank, related_name = '%(class)s_logocreated',)
    phone = PhoneNumberField()
    address = models.ForeignKey(Address)
    website = models.URLField()
    name = models.CharField(max_length=64)

    def __unicode__(self):
        return self.name

class ImageBank(models.Model):
    business = models.ForeignKey('Business', related_name='%(class)s_business')
    image = models.ImageField(upload_to="images/bank")

    def url(self):
        return self.image.url

    def __unicode__(self):
        return unicode(self.business) + " : " + unicode(self.image)

Store Model:

class Store(models.Model):
    business = models.ForeignKey(Business,null=True, related_name='business_creator_set')
    condition = models.CharField(verbose_name='What do customers have to do?',max_length = 50)
    reward = models.CharField(verbose_name='What do customers win?',max_length = 50)
    display = models.BooleanField(default=True)
    date_created = models.DateTimeField(default=datetime.now)


    def __unicode__(self):
        return self.condition + ", " + self.reward
+3
source share
1 answer

Try to do something like this:

...
class ImageBank(models.Model):
    business = models.ForeignKey('Business', related_name='%(class)s_business')
....

Also, if this does not work, try changing the name related_name in the Business.logo field to something that is not logo_id. logo_id is what the database uses for the field and may have a conflict.

+1
source

All Articles