我的一个 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.
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/