当我创建Django mod时,我得到“parent_id may not NULL”

2024-10-01 11:27:26 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在创建自己的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)

我怎样才能做到这一点?在

谢谢。在


Tags: 模型true界面modelstopgroup情况成员
2条回答

Django evolution可以在不丢失完整数据库的情况下解决此类问题

在将blank=True, null=True添加到parent字段定义之前,我创建了数据库。syncdb无法处理这种类型的更改,因此Django没有接受我的更改。在

我删除了我的数据库,让syncdb创建另一个,它工作得很好。在

相关问题 更多 >