Django—问题—生成迁移脚本时报错:You are trying to add a non-nullable field 'gender' to interfaces without a default

You are trying to add a non-nullable field 'gender' to interfaces 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

原因是我之前已经生成过一版数据库,这时我再添加一个键,就报错了

解决方案:加上null=True,允许为空,这样就不会报错了

参考:https://www.codetd.com/article/6194385

原文地址:https://www.cnblogs.com/erchun/p/14489966.html