$ python manage.py makemigrations You are trying to add a non-nullable field 'name' to course without a default; we can't do that (the database needs something to populate existing rows). Please selec

问题:

$ python manage.py makemigrations
You are trying to add a non-nullable field 'name' to course 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

原因:由于之前已经存在的表,某些字段为没有默认值,这时候添加的时候,需要给定默认值

解决:

方法1:每个报错的字段添加   

blank=True, null=True

方法2:需要添加的字段太多,

         本地自己做项目的话,

       删除之前的数据库,删除migrations,

     重新生成数据

猜你喜欢

转载自www.cnblogs.com/venicid/p/11922861.html