Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fastest Way to Update a bunch of records in queryset in Django

I have a queryset with a few million records. I need to update a Boolean Value, fundamentally toggle it, so that in the database table the values are reset. What's the fastest way to do that?

I tried traversing the queryset and updating and saving each record, that obviously takes ages? We need to do this very fast, any suggestions?

like image 881
ramdaz Avatar asked Jan 26 '10 18:01

ramdaz


1 Answers

See the documentation:

Entry.objects.all().update(value= not F('value'))
like image 171
Felix Kling Avatar answered Sep 23 '22 17:09

Felix Kling