Is there a way to delete all Events? #153
-
I'd like to reset the logging I'm using pghistory for because some of the models don't exist anymore and some model instances were deleted. How can I delete the full history or all Events? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
There are a few ways to do this:
Note, if you're using import pgtrigger
with pgtrigger.ignore("app_label.MyModelEvent:append_only"):
... Finally, django-pghistory disables cascading deletion behavior by default. If you'd like change this globally, do this in your settings: import pghistory
PGHISTORY_OBJ_FIELD = pghistory.ObjForeignKey(on_delete=models.CASCADE) This can also be supplied to |
Beta Was this translation helpful? Give feedback.
There are a few ways to do this:
If the model still exists in your code base:
Note - Use
from django.apps import apps
and then iterate over every model withapps.get_models
. Any model with thepgh_event_models
attribute has history modelsIf the model no longer exists:
Your best option here is raw SQL. Find the table name of the event model (usually it's the model's table name plus
_event
) and then do:Note, if you're using
append_only…