Why can't I save my model with a generic relation twice in Django?
- by e-satis
I got a model TrackedItem with a generic relation linking to any model it is supposed to track.
If I do that:
t = TrackedItem(content_object=MyModel)
t.save()
t.save()
I get :
IntegrityError: (1062, "Duplicate entry '1' for key 'PRIMARY'")
Indeed, the first save has created an entry with "1" as a PK. But the second save should not insert, it…