1. 程式人生 > 其它 >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: 解決方法

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="預設值")