2👍
✅
You have duplicate M2M
with Tag
as albums
you my want to change that for Album
. Also good idea to have related name as well
tags = models.ManyToManyField(Tag, blank=True)
albums = models.ManyToManyField(Tag, blank = True,)
change to
tags = models.ManyToManyField(Tag, blank=True, related_name="img_tags")
albums = models.ManyToManyField(Album, blank = True, related_name="img_albums")
0👍
When you have two fields that are foreign keys to the same model, you need to provide a related_name
so django knows what to call the relation. That’s what the error is saying.
So, update your model by giving your relations a unique name:
tags = models.ManyToManyField(Tag, blank=True, related_name='image_tags')
albums = models.ManyToManyField(Tag, blank = True, related_name='album_tags')
However, what you probably meant is this:
tags = models.ManyToManyField(Tag, blank=True)
albums = models.ManyToManyField(Album, blank=True)
Source:stackexchange.com