python - Django DateTimeField 定义为 blank=True, null=True 但不允许 null

标签 python django

我的一个 Django 模型中有一个 DateTimeField。

    completed_date = models.DateTimeField('date completed', blank=True, null=True)

我已将其定义为允许空白值和空值。但是,当我尝试创建模型的实例时,出现以下错误:

IntegrityError at /admin/tasks/project/add/

tasks_project.completed_date may not be NULL

我使用的是 Django 1.25 和 Python 2.7。有人知道为什么会这样吗?我能做些什么来解决这个问题吗?

我找到了一个 ticket that describes the same problem ,但它在 4 年前已修复,因此我认为它现在一定已经集成到 Django 中了!

最佳答案

django syncdb and an updated model

来自那个问题/答案:

Django doesn't support migrations out of the box. There is a pluggable app for Django that does exactly that though, and it works great. It's called South.

http://south.aeracode.org/

Havent used django in a while, but i seem to remember that syncdb does perform alter commands on db tables. you have to drop the table then run again and it will create again.

关于python - Django DateTimeField 定义为 blank=True, null=True 但不允许 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5368345/

相关文章:

python - 检查元组的第一个元素由定义的字符串指定的列表

python - 如何在Python中进行指数非线性回归

python - Nginx 调试日志记录级别

django - django 模型可以有嵌入类吗?

python - Django 和 python3

关于 settings.DEBUG 的 django-celery 警告

python - WordNetLemmatizer : Different handling of wn. ADJ 和 wn.ADJ_SAT?

python - 通过接收json对象通过递归在python中构建一棵树

django - 如何在 django 中编写动态站点地图,我的不工作

python - Django 忽略测试数据库设置