Django项目中 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: 解决方法


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

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="默认值")

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM