我创造我自己的Group模型;我不是指内置Group模型。我希望每个hroup为另一基团(它的父)的一员,但不具有父组的一个“顶部”基团。

管理界面不会让我不输入父创建组。我得到的错误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)

我怎样才能做到这一点?

感谢。

有帮助吗?

解决方案

我创建数据库I加入之前的 blank=True, null=True 以在 parent 字段的定义。执行syncdb不能处理这种类型的变化,所以Django的不是我的变化回升。

我删除了数据库,并让执行syncdb创建另一个和它工作得很好。

其他提示

Django的进化会让你出了这种问题不会丢失你的完整的数据库

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top