Reputation: 5190
I have an object called PTORequest which have a history field for storing HistoricalRecords of it.
history = HistoricalRecords()
I have not mentioned cascade_delete_history=True
while creating history column which would automatically cascade history records.
How do I delete all the objects and their historical records from PTORequest table without doing model changes and migrations?
One thing I can think of is this:
for i in PTORequest.objects.all():
print i.history.all().delete()
print i.delete()
Is there any other efficient way to do this?
I'm using Django 1.11
Upvotes: 0
Views: 809
Reputation: 15738
You can get all object historical records by Querying history on model class
So something like this:
PTORequest.history.all().delete()
Upvotes: 2