How does one purge a database of old revisions?

Viewed 602

How might I remove old revisions from the Wagtail database? I see that every time I make a change the previous revision of the page is kept in the database ... very nice, but how do I "take out the trash?"

In other words: "okay, this page is now finished, and I don't wish to keep previous revisions of it anymore." You'd think this would be easy – but, where is it?

1 Answers

Revisions are stored in the wagtail.core.models.PageRevision model, which is the wagtailcore_pagerevision table in the database. To delete all revisions for a given page, you can run the following from ./manage.py shell:

from wagtail.core.models import PageRevision
PageRevision.objects.filter(page_id=123).delete()

Note that the 'save as draft' and 'submit for moderation' workflows also work by saving PageRevision entries, so you should only do this after the page has been published in the state that you want to keep.

Related