Skip to content

Is there a way to delete all Events? #153

Closed Answered by wesleykendall
LaundroMat asked this question in Q&A
Discussion options

You must be logged in to vote

There are a few ways to do this:

  1. If the model still exists in your code base:

    from myapp.models import MyModel
    
    for event_model in MyModel.pgh_event_models.values():
        event_model.objects.all().delete()

    Note - Use from django.apps import apps and then iterate over every model with apps.get_models. Any model with the pgh_event_models attribute has history models

  2. If 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:

    from django.db import connection
    
    with connection.cursor() as cursor:
        cursor.execute("DELETE FROM my_event_model_table")

Note, if you're using append_only…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by wesleykendall
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #131 on September 02, 2024 19:10.