Django error object has no attribute 'update'

后端 未结 4 1002
[愿得一人]
[愿得一人] 2020-12-15 04:34

UPDATE

I was doing some maintenance on the server and rebooted... once it came back the code worked just fine... which actually makes me to worry ju

4条回答
  •  春和景丽
    2020-12-15 04:53

    Encountered this behavior and used a "filter" then update works as expected. For example:

     Students.objects.select_for_update().filter(id=3).update(score = 10)
    

    Just FYI: Unless you are handling transactions, modifying each field separately using save() might create data inconsistency in a multi-threaded environment. By the time threadA calls save() on a model, another threadB could have changed the model fields and saved. In which case threadA has to read the updated model and change.

    This was on Django 1.6.2

提交回复
热议问题