其他分享
首页 > 其他分享> > 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="默认值")

 

标签:Quit,now,default,value,existing,models,默认值
来源: https://www.cnblogs.com/zs0621/p/16088960.html