django在进行makemigrations 出现 timezone.now报错
老眼 2018-02-20 21:16:33
分 享


问题现象


You are trying to add a non-nullable field 'wor_creator' to workorderrolesmgmts without a default; we can't do that (the database needs something to populate existing rows).

Please select a fix:

 1) Provide a one-off default now (will be set on all existing rows with a null value for this column)

 2) Quit, and let me add a default in models.py

Select an option:  1

Please enter the default value now, as valid Python

The datetime and django.utils.timezone modules are available, so you can do e.g. timezone.now

Type 'exit' to exit this prompt

>>>  


这段话的意思是 wor_creator 字段没有默认值,而且非Null 那么 

1) 指定一个一次性的值供更改数据库时使用。

2) 停止当前操作,在 models.py 中给定默认值,然后再来migrate。


解决方法


在最后提示


The datetime and django.utils.timezone modules are available, so you can do e.g. timezone.now

Type 'exit' to exit this prompt

>>>  


输入 >>>timezone.now() 即可

吐槽一下

游客

所有吐槽
  • 暂时还没有吐槽,赶紧来吐槽!