R
R
raiboon2015-04-10 16:51:06
Django
raiboon, 2015-04-10 16:51:06

How to remove many django objects?

Logically:

model.objects.filter(
                date__gte=date.fromtimestamp(start),
                date__lte=date.fromtimestamp(end)
            ).delete()

There are quite a few entries. And I see hundreds of requests like this:
DEBUG:django.db.backends:(0.085) DELETE FROM "bla-bla-bla" WHERE "bla-bla-bla"."id" IN (77787523, 77787522, 77787521, 77787520, 77787519, 77787518, 77787517, 77787516, 77787515, 77787514, 77787513, 77787512, 77787511, 77787510, 77787509, 77787508, 77787507, 77787506, 77787505, 77787504, 77787503, 77787502, 77787501, 77787500, 77787499, 77787498, 77787497, 77787495, 77787494, 77787493, 77787492, 77787491, 77787490, 77787489, 77787488, 77787487, 77787486, 77787485, 77787484, 77787483, 77787482, 77787481, 77787480, 77787479, 77787478, 77787477, 77787476, 77787475, 77787474, 77787473, 77787472, 77787471, 77787470, 77787469, 77787468, 77787467, 77787466, 77787465, 77787464, 77787463, 77787462, 77787461, 77787460, 77787459, 77787458, 77787457, 77787456, 77787455, 77787454, 77787453, 77787452, 77787451, 77787450, 77787449, 77787448, 77787447, 77787446, 77787445, 77787444, 77787443, 77787442, 77787441, 77787440, 77787439, 77787438, 77787437, 77787436, 77787435, 77787434, 77787433, 77787432, 77787431, 77787430, 77787429, 77787428, 77787427, 77787426, 77787425, 77787424, 77787423); args=(77787523, 77787522, 77787521, 77787520, 77787519, 77787518, 77787517, 77787516, 77787515, 77787514, 77787513, 77787512, 77787511, 77787510, 77787509, 77787508, 77787507, 77787506, 77787505, 77787504, 77787503, 77787502, 77787501, 77787500, 77787499, 77787498, 77787497, 77787495, 77787494, 77787493, 77787492, 77787491, 77787490, 77787489, 77787488, 77787487, 77787486, 77787485, 77787484, 77787483, 77787482, 77787481, 77787480, 77787479, 77787478, 77787477, 77787476, 77787475, 77787474, 77787473, 77787472, 77787471, 77787470, 77787469, 77787468, 77787467, 77787466, 77787465, 77787464, 77787463, 77787462, 77787461, 77787460, 77787459, 77787458, 77787457, 77787456, 77787455, 77787454, 77787453, 77787452, 77787451, 77787450, 77787449, 77787448, 77787447, 77787446, 77787445, 77787444, 77787443, 77787442, 77787441, 77787440, 77787439, 77787438, 77787437, 77787436, 77787435, 77787434, 77787433, 77787432, 77787431, 77787430, 77787429, 77787428, 77787427, 77787426, 77787425, 77787424, 77787423)

Those. he selected all the records and began to delete them in groups ... What for? How to delete normally using orm?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vadim Shandrinov, 2015-04-10
@raiboon

The thing is that Djanga sends deletion signals at the ORM level, all these pre_delete and post_delete
https://docs.djangoproject.com/en/dev/topics/signals/
Therefore, all deleted objects are pulled to send messages to dependent objects :( so mass deletion looks like extracting all IDs, sending signals, and then delete from ... where id in (<and here are heaps of these id separated by commas>).
Therefore, to delete several million records, for example, I use only RAW SQL, alas.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question