对于以下查询,django中是否有任何queryset等效项。
UPDATE table
SET field = REPLACE(field, 'string', 'anothervalue')
WHERE field LIKE '%string%';发布于 2019-05-02 19:12:42
我找到了解决方案,我们需要使用Replace DB函数。看起来像下面这样。
from django.db.models import Value
from django.db.models.functions import Replace
Model.objects.update(field=Replace(
'field', Value('string'), Value('anothervalue')
))有关更多信息,请访问official docs.
https://stackoverflow.com/questions/55949806
复制相似问题