Django表示“id可能不为NULL”但为什么呢? [英] Django says the "id may not be NULL" but why is it?

查看:563
本文介绍了Django表示“id可能不为NULL”但为什么呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我今天要疯了我只是试图插入一个新的记录,它抛出一个post_blogpost.id可能不是NULL的错误。这是我的模型:

  class BlogPost(models.Model):
title = models.CharField(max_length = 100)
slug = models.SlugField(max_length = 100)
who = models.ForeignKey(User,default = 1)
when = models.DateTimeField()

介绍= models.TextField(blank = True,null = True)
content = models.TextField(blank = True,null = True)

counter = models.PositiveIntegerField(default = 0)

published = models.BooleanField(default = False)
css = models.TextField(blank = True,null = True)

class Meta:
订单=('-when','id')

模型下面有一些功能我也不会把它们全部包含在这里。他们的名字是: content_cache_key clear_cache __ unicode __ 读取读取 processed_content



我正在通过管理员添加...我的头发不足。

解决方案

我唯一可以想到的是,表模式已经从模型中脱离,因为有人从表的PK中删除了 AUTOINCREMENT 属性。


I'm going crazy today. I just tried to insert a new record and it threw back a "post_blogpost.id may not be NULL" error. Here's my model:

class BlogPost(models.Model):
    title   = models.CharField(max_length=100)
    slug    = models.SlugField(max_length=100)
    who     = models.ForeignKey(User, default=1)
    when    = models.DateTimeField()

    intro   = models.TextField(blank=True, null=True)
    content = models.TextField(blank=True, null=True)

    counter = models.PositiveIntegerField(default=0)

    published = models.BooleanField(default=False)
    css = models.TextField(blank=True, null=True)

    class Meta:
        ordering = ('-when', 'id')

There are a number of functions beneath the model too but I won't include them in full here. Their names are: content_cache_key, clear_cache, __unicode__, reads, read, processed_content.

I'm adding through the admin... And I'm running out of hair.

解决方案

The only thing I can think of is that the table schema has become desynchronized from the model in that someone removed the AUTOINCREMENT attribute from the PK of the table.

这篇关于Django表示“id可能不为NULL”但为什么呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆