开发者

Django, Cannot assign None, does not allow null values

开发者 https://www.devze.com 2022-12-12 22:21 出处:网络
i have this models.py import datetime from django.db import models from tinymce import models as tinymce_models

i have this models.py

import datetime
from django.db import models
from tinymce import models as tinymce_models
from filebrowser.fields import FileBrowseField
开发者_如何学Go
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?


 #for sql 'now()' value use
 published = models.DateField('Published', auto_now_add=True)
 #to allow sql null
 published = models.DateField('Published', null=True, blank=True)


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:

published = models.DateField('Published', null=True, blank=True)
0

精彩评论

暂无评论...
验证码 换一张
取 消