Deze fout kan optreden wanneer meerdere threads tegelijk dezelfde ManyToMany-relatie toevoegen. Gebruik dan een through-model met get_or_create, omdat die atomaire werking concurrentieproblemen voorkomt.
ArticlePublication.objects.get_or_create(
article=article,
publication=pub
)
Je kunt ook de through-tabel direct aanspreken:
article.publications.through.objects.get_or_create(
article=article,
publication=pub
)