gpt4 book ai didi

python - 为什么我收到 IntegrityError : NOT NULL constraint failed

转载 作者:行者123 更新时间:2023-12-01 02:59:23 24 4
gpt4 key购买 nike

IntegrityError: NOT NULL constraint failed: app_userprofile.email

该字段如下所示:

email = models.CharField(max_length=100, blank=True, default=None)

我不明白。创建模型实例但未设置电子邮件字段时会发生错误。但它是空白的,而且是 charfield,并且 None 如果不被覆盖,为什么会发生这种情况?

最佳答案

有两个选项:

  1. set null = True 如果您想在数据库中保存 null 值,则使用该设置。
  2. set blank = True 用于表单验证。您可以调用保存表单而不需要该字段中的值。

在当前问题中,您只需添加 null = True

email = models.CharField(max_length=100, blank=True, null=True, default=None)

关于python - 为什么我收到 IntegrityError : NOT NULL constraint failed,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43956703/

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