Django,无法分配 None,不允许空值
我有这个 models.py
import datetime
from django.db import models
from tinymce import models as tinymce_models
from filebrowser.fields import FileBrowseField
class ItemWithMedia(models.Model):
created = models.DateTimeField(auto_now_add=True)
modified = models.DateTimeField(auto_now=True)
class Actual(ItemWithMedia):
published = models.DateField('Published')
title_hr = models.CharField('(hr)', max_length=200)
title_en = models.CharField('(en)', max_length=200)
body_text_hr = models.TextField('(hr)')
body_text_en = models.TextField('(en)')
def __unicode__(self):
return self.title_hr
class Meta:
verbose_name = "Aktualno"
verbose_name_plural = "Aktualni"
ordering = ['-published']
,当我尝试在管理站点中创建新项目时出现此错误: 无法分配 None:“Actual.published”不允许空值。
可能是什么问题?
i have this models.py
import datetime
from django.db import models
from tinymce import models as tinymce_models
from filebrowser.fields import FileBrowseField
class ItemWithMedia(models.Model):
created = models.DateTimeField(auto_now_add=True)
modified = models.DateTimeField(auto_now=True)
class Actual(ItemWithMedia):
published = models.DateField('Published')
title_hr = models.CharField('(hr)', max_length=200)
title_en = models.CharField('(en)', max_length=200)
body_text_hr = models.TextField('(hr)')
body_text_en = models.TextField('(en)')
def __unicode__(self):
return self.title_hr
class Meta:
verbose_name = "Aktualno"
verbose_name_plural = "Aktualni"
ordering = ['-published']
and i get this error when i try to create new item in admin site:
Cannot assign None: "Actual.published" does not allow null values.
what could be the problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要将参数“null = True,blank = True”添加到published的定义中,这样它就不会在数据库中创建为NOT NULL列:
You need to add the parameters "null=True, blank=True" to the definition of published, that way it won't be created as a NOT NULL column in the database: