Django 常用常见问题

models中,对sqlites数据更新时,updatetime不更新问题现象:使用批量更新的.update操作,数据更新了,但是updatetime不更新。而单独更新.save()则正常更新。说明:auto_now_add will set the field to the current time when an object is created and auto_now will set t
摘要由CSDN通过智能技术生成
models中,对sqlites数据更新时,updatetime不更新问题

现象:使用批量更新的.update操作,数据更新了,但是updatetime不更新。而单独更新.save()则正常更新。

说明:auto_now_add will set the field to the current time when an object is created and auto_now will set the field to the current time when an object is created or updated
auto_now_add是在创建字段的时候会自动记录创建时间。
auto_now是在更新对象和更新的时候记录更新时间。

原因:The field is only automatically updated when calling Model.save(). The field isn’t updated when making updates to other fields in other ways such as QuerySet.update(), though you can specify a custom value for the field in an update like that.
这个字段只有在调用Mode.save()时才会自动更新。当使用批量插入的QuerySet.update()不会更新该字段,你可以通过指定一个特定的值来更新该字段。

参考:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值