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