jazzband / django-auditlog

A Django app that keeps a log of changes made to an object.
MIT License
1.11k stars 409 forks source link

AuditLog error when cloning objects #664

Open raayu83 opened 1 month ago

raayu83 commented 1 month ago

I'm trying to clone objects including their m2m fields using a solution I found on StackOverflow.

Unfortunately I get the following error: null value in column "object_pk" of relation "auditlog_logentry" violates not-null constraint

I assume this is because the cloned objects pk field has to be set to None in order for it to be assigned with a new ID automatically.

Is there any way to work around this?

jcgiuffrida commented 3 weeks ago

You can get around this by manually assigning an id to the copied object but be very careful it's not an ID already in use, or you'll overwrite something else. You could also probably temporarily unregister the model with AuditLog, which disables the signals.

raayu83 commented 3 weeks ago

Since these seemed more like hacks than an actual solution I switched to django-simple-history which suits my usecase better