Django部分更新 [英] Django partial update
问题描述
我有两个线程,一个运行类似 update t set ColA = foo
的东西,另一个运行 update t set ColB = foo
.如果他们在执行原始SQL语句,则不会有争用,但是由于Django获取并保存了整行,因此会出现竞争条件.
I have two threads, one which runs something like update t set ColA=foo
and the other runs update t set ColB=foo
. If they were doing raw SQL statements there would be no contention, but since Django gets and saves the entire row, a race condition can occur.
有什么办法告诉Django我只想保存一列吗?
Is there any way to tell Django that I just want to save a certain column?
推荐答案
您正确的说, save
将更新整行,但是Django有一个 update
可以完成所有操作你描述.
You are correct that save
will update the entire row but Django has an update
which does exactly what you describe.
https://docs.djangoproject.com/en/stable/ref/models/querysets/#update
这篇关于Django部分更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!