1

我已经看到用户提出了许多问题,这些问题与表单的 django 错误作斗争:

IntegrityError at... X 列中的空值违反非空约束

通常这是因为他们只在原始操作之后才更新了它们models.py,并且他们需要手动更新有问题的 SQL 表,或者使用南迁移。但是,尽管完全删除了数据库架构并使用. 有人可以解释一下吗?显然,我可以只更新 Postgre 中的列以删除 NOT NULL,但我担心这种情况正在发生。null=True, blank=Truesyncdbsyncdbmodels.py

models.py

class TopTen(models.Model):
    toptenuser = models.ForeignKey(TopTenUser)
    date_in = models.DateTimeField()
    date_out = models.DateTimeField(null=True, blank=True)
    active = models.BooleanField()

syncdb

> (venv)richard@ubuntu:~/DjangoProjects/Heroku/mytopten$ heroku run python manage.py syncdb
> Running `python manage.py syncdb` attached to terminal... up, run.5406
> Creating tables ...
> Creating table auth_permission
> Creating table auth_group_permissions
> Creating table auth_group
> Creating table auth_user_groups
> Creating table auth_user_user_permissions
> Creating table auth_user
> Creating table django_content_type
> Creating table django_session
> Creating table django_site
> Creating table django_admin_log
> Creating table mytopten_toptenuser
> Creating table mytopten_topten
> Creating table mytopten_song_toptens
> Creating table mytopten_song

然而,我第一次runserver尝试进入 TopTen 实例时:

IntegrityError:“date_out”列中的空值违反非空约束

我在这里做错了吗?谢谢。

4

0 回答 0