因為之前數(shù)據(jù)庫中已經(jīng)有數(shù)據(jù)了知染,現(xiàn)在加了一個字段烈掠,這個字段沒有默認值彤钟,它不知道該怎么填什么東西来候,所以它會報錯,并且有兩種解決方法: 1.在當前cmd報錯狀態(tài)下輸入1逸雹,然后輸入字符串营搅,如果是時間,則輸入timezone.now 2.在models下添加default即可
name = models.CharField(max_length=50)
執(zhí)行:python manage.py makemirations出現(xiàn)以下錯誤:
You are trying to add a non-nullable field 'name' to contact without a default; we can't do that (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 let me add a default in models.py
Select an option:?
解決方法:
先給'name'任意初始值:name = models.CharField(max_length=50, default='abc')
然后執(zhí)行:python manage.py makemirations
再執(zhí)行:python manage.py migrate
再將default刪去梆砸,即執(zhí)行:name = models.CharField(max_length=50)
執(zhí)行:python manage.py makemirations
再執(zhí)行:python manage.py migrate
原文鏈接:https://blog.csdn.net/check2255/java/article/details/70338443