django-sortedm2m
django-sortedm2m copied to clipboard
[bug] Cannot set an existing field
Versions
django-sortedm2m==3.0.0 Django==3.0.2
Code
class Parent(Model):
children = SortedManyToManyField('Child')
The bug
Given that I have a Parent instance with 3 Children with ids 1, 2, 3. When I run the below lines under Django 3.0.2
child = Children.objects.get(id=1)
parent.children.set([child])
I get
IntegrityError: duplicate key value violates unique constraint ... already exists.
But if I run it under Django 2.x.x, the code runs succesfully, and the parent instance has 1 child after that.