我们有一个Django后端的运行实例.在一些型号上,我们使用Charfield作为主键,因为它是满足旧需求的最佳解决方案.现在我们需要添加一个基本的int id,如下所示
id = models.AutoField(primary_key=True)
让老查菲尔德保持primary_key=False
岁.
我从旧的主键属性中删除了primary_key=True
标志,并触发了./manage.py makemigrations
.如果我没有声明任何主键,Django会像上面提到的那样生成它的普通id.但是在trigger之后,Djang会要求这个模型的旧条目的默认值,比如:
It is impossible to add a non-nullable field 'id' to anrede without specifying a default. This is because 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 manually define a default value in models.py.
因为它是唯一的字段,所以我不能使用任何静态内容.那么,如何才能在不删除旧迁移的情况下仍然进行迁移呢?