小编Gre*_*reg的帖子

创建我的Django模型时,我得到"parent_id可能不是NULL"

我正在创建自己的Group模型; 我不是指内置Group模型.我希望每个hroup都是另一个组(它的父组)的成员,但是有一个"top"组没有父组.

管理界面不允许我在不输入父级的情况下创建组.我收到了错误personnel_group.parent_id may not be NULL.我的Group模型看起来像这样:

class Group(models.Model):
    name = models.CharField(max_length=50)
    parent = models.ForeignKey('self', blank=True, null=True)
    order = models.IntegerField()
    icon = models.ImageField(upload_to='groups', blank=True, null=True)
    description = models.TextField(blank=True, null=True)
Run Code Online (Sandbox Code Playgroud)

我怎么能做到这一点?

谢谢.

python database django models

4
推荐指数
1
解决办法
3463
查看次数

标签 统计

database ×1

django ×1

models ×1

python ×1