gpt4 book ai didi

python - 如何为自动生成的 OneToOneField 关系设置默认值?

转载 作者:行者123 更新时间:2023-12-01 07:28:00 26 4
gpt4 key购买 nike

我有两个他们喜欢的模型类:


from django.db import models
from django.urls import reverse

class Place(models.Model):
address = models.CharField(max_length=80)


class Author(Place):
name = models.CharField(max_length=50)

但是当我想执行 makemigartions django 时会显示以下错误:

You are trying to add a non-nullable field 'place_ptr' to author 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
Select an option:

我在作者表中有一些数据,但我不想删除这些数据。

请问有谁可以帮助我吗?

最佳答案

您可以删除特定应用程序的旧迁移文件或整个迁移文件夹,然后执行 python manage.py makemigrations <app_name>
如果这不是您想要的解决方案,那么 you can find the solution here.

关于python - 如何为自动生成的 OneToOneField 关系设置默认值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57354784/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com