Django DateTimeField auto_now_add 不起作用 [英] Django DateTimeField auto_now_add not working
本文介绍了Django DateTimeField auto_now_add 不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在其中一个模型中,我设置了一个时间戳字段,如下所示:
In one of the model i have set one timestamp field as follows:
created_datetime = models.DateTimeField(auto_now_add = True)
虽然在 shell 中我能够创建一个 obj 并保存它,但是在我的应用程序中它引发了一个异常,即 created_datetime 字段不能为空.
While in shell i am able to create a obj and save it, however in my application it is raising a exception that created_datetime field cannot be null.
困惑哪里出了问题!!如何重新爱上它.
Confused where things went wrong!! How to reslove it.
推荐答案
你可以这样做
created_datetime = models.DateTimeField(auto_now_add=True, auto_now=False)
这篇关于Django DateTimeField auto_now_add 不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文