问题:

$ 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,

     重新生成数据

$ 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

 

相关文章:

  • 2021-08-18
  • 2022-12-23
  • 2021-10-21
  • 2021-03-31
  • 2021-09-11
  • 2022-01-20
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-07-14
  • 2022-12-23
  • 2021-08-21
  • 2021-09-05
  • 2021-08-10
  • 2021-08-10
  • 2021-07-12
相关资源
相似解决方案