select_for_update in development Django

前端 未结 1 1082
清歌不尽
清歌不尽 2020-12-16 22:49

The Django documentation states that:

If you were relying on “automatic transactions” to provide locking between select_for_update() and a subsequen

相关标签:
1条回答
  • 2020-12-16 23:26

    select_for_update will only lock the selected row within the context of a single transaction. If you're using autocommit, it won't do what you think it does, because each query will effectively be its own transaction (including the SELECT ... FOR UPDATE query). Wrap your view (or other function) in transaction.atomic and it'll do exactly what you're expecting it to do.

    0 讨论(0)
提交回复
热议问题