Pregunta

How to delete specific number of entries from the database? I did something like this

EntriesToDelete=Statusmessages.objects.filter(time__lt=date)[:30000]
EntriesToDelete.delete()

But I get an error which says: AssertionError. Cannot use 'limit' or 'offset' with delete.

How can I specify the number of entries to be deleted.

¿Fue útil?

Solución

You could do it like this:

Statusmessages.objects.filter(pk__in=Statusmessages.objects.filter(time__lt=date).values_list('pk')[:30000]).delete()
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top