首页 > 解决方案 > 如何在 django 中进行迁移?

问题描述

最初我迁移了一个应用程序模型,之后我在那里添加了一个字段

pol_id = CharField(max_length=25, unique=True)

现在,如果我正在运行 makemigrations 它向我展示

You are trying to add a non-nullable field 'pol_id' to Health 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,但我不能在 pol_id 中添加 null=True,是否有任何硬迁移命令来解决这个问题?

标签: djangodjango-models

解决方案


它出现是因为您没有在该字段中指定默认值。您完全不必感到惊讶。

如果不需要default为models.py中的字段指定,只需选择选项编号1,并输入''为默认值。


推荐阅读