Booleand 字段和 Postgresql 的 IntegrityError

发布于 2024-09-03 09:03:43 字数 470 浏览 5 评论 0原文

我有这个简单的博客模型:

class Blog(models.Model):

    title = models.CharField(_('title'), max_length=60, blank=True, null=True)
    body = models.TextField(_('body'))
    user = models.ForeignKey(User)  
    is_public = models.BooleanField(_('is public'), default = True)

当我在管理界面中插入博客时,我收到此错误:

IntegrityError at /admin/blogs/blog/add/

null value in column "is_public" violates not-null constraint

为什么???

I have this simple Blog model:

class Blog(models.Model):

    title = models.CharField(_('title'), max_length=60, blank=True, null=True)
    body = models.TextField(_('body'))
    user = models.ForeignKey(User)  
    is_public = models.BooleanField(_('is public'), default = True)

When I insert a blog in admin interface, I get this error:

IntegrityError at /admin/blogs/blog/add/

null value in column "is_public" violates not-null constraint

Why ???

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

翻了热茶 2024-09-10 09:03:43

唔。奇怪的怪癖。无法说出为什么会发生这种情况,因为默认值应该意味着它始终被设置,但是如果您应用相关的架构更改/迁移

is_public = models.BooleanField(_('is public'), default , 这应该可以解决它=真,null=真)

Hmm. Odd quirk. Can't say why it is happening because the default should mean it's always set, but this should fix it, if you apply the relevant schema change/migration

is_public = models.BooleanField(_('is public'), default=True, null=True)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文