44👍
✅
You could do it like this:
pks = (Statusmessages.objects
.filter(time__lt=date)
.values_list('pk')[:30000])
Statusmessages.objects.filter(pk__in=pks).delete()
👤jpic
0👍
use this:
Statusmessages.objects.filter(pk__in=Statusmessages.objects.filter(time__lt=date).values_list('pk', flat=True)[:30000]).delete()
use flat=True
, if not then is a tuple and raise exception:
{NotSupportedError}(1235, "This version of MySQL doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery'")
- Django widget override template
- Create a canonical "parent" product in Django Oscar programmatically
- How can I make a fixture out of QuerySet in django?
- Problem launching docker-compose : python modules not installed
- You cannot add messages without installing django.contrib.messages.middleware.MessageMiddleware
0👍
If you get the following error:
django.db.utils.NotSupportedError: (1235, "This version of MariaDB doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery'")
Force evaluate the list of ids with list().
Here’s an example:
sessions_to_delete = LoginSession.objects.filter(user=self.userProfile)[3:]
pks_of_sessions_to_delete = list(sessions_to_delete.values_list("pk", flat=True))
LoginSession.objects.filter(pk__in=pks_of_sessions_to_delete).delete()
Source:stackexchange.com