欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

Django | 模型类变更后生成迁移文件,报错:You are trying to add a non-nullable field 'BookName' to BookInfo without a default....

程序员文章站 2022-07-02 17:12:59
报错: You are trying to add a non-nullable field 'BookName' to BookInfo without a default; we can't do that (the database needs something to populate ex ......

报错:

you are trying to add a non-nullable field 'bookname' to bookinfo 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)

 2) quit, and let me add a default in models.py

 

原因:

在模型类中添加了一个非空字段,而该模型类对应的表中,已经存在数据,而这些现存的数据并没有新增字段的值