[Django]-Django – bulk update arrayfield rows postgres

0πŸ‘

I don’t think its possible to do currently, I think the best you can do is to do it is to iterate over the models.

for model in ModelA.objects.all():
    for val in model_a.colA:
        val = val + 1
    model.save()

You can do this as an atomic transaction as well if you wish.. Although it may be worth considering if this field really should be an array field.

πŸ‘€Sayse

0πŸ‘

You can try using the django-bulk-update package. Although I’m not sure whether it can handle ArrayField

πŸ‘€ilse2005

-2πŸ‘

Why not do a database migration? Django’s database migration system should allow you to do this easily, I believe.

πŸ‘€ubadub

Leave a comment