Go教程

Django项目中 Provide a one-off default now (will be set on all existing rows with a null value for this

本文主要是介绍Django项目中 Provide a one-off default now (will be set on all existing rows with a null value for this,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

在已有数据的表中新增字段时,会弹出下面的步骤让你来操作

Tracking file by folder pattern: migrations
It is impossible to add a non-nullable field 'Publisher' to book without specifying a default. This is because 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 manually define a default value in models.py.   #这是退出后自己输入
Select an option:

 

解决方法1:  在输入框中选择    1  会弹出下面的提示

Please enter the default value as valid Python.
The datetime and django.utils.timezone modules are available, so it is possible to provide e.g. timezone.now as a value.
Type 'exit' to exit this prompt

然后输入默认的值:"1"   这里的值要记得加引号

解决方法2:在models.py文件中 将新增的字段添加默认值

例子:addr =models.CharField(max_length,default="默认值")

 

这篇关于Django项目中 Provide a one-off default now (will be set on all existing rows with a null value for this的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!