django项目 在进行数据生成迁移文件makemigrations时报Please select a fix:...

问题:django项目 在进行生成迁移文件:python .\manage.py makemigrations时,报错,如图

 

 原因:在之前项目新建模型的时候,缺少一个字段进行迁移了然后数据表中又产生了数据,后面又发现少了个字段然后进行添加此字段,再进行生成迁移文件时就报错了。

解释:

Provide a one-off default now (will be set on all existing rows with a null value for this column)

现在提供一个一次性默认值(将在所有现有行上设置此列的空值)

Quit, and let me add a default in models.py

退出,让我在models.py中添加一个默认值

解决:

因为我们需要加字段,所以我我们应该选择第一个

Select an option:  1
Please enter the default value now, as valid Python
The datetime and django.utils.timezone modules are available, so you can do e.g. timezone.now()
Type 'exit' to exit this prompt

>>>  1

 

然后进行迁移文件文件就行了

python manage.py migrate

 

posted @ 2022-08-08 23:37  无渊  阅读(329)  评论(0)    收藏  举报
返回顶端