当使用Django的Group模型时,Django-mptt初始迁移

时间:2015-11-06 10:33:40

标签: django django-mptt

我正在看看django-mptt,发现我可以使用它与Django的内置Group模型。所以,我按照文档

中提到的步骤进行操作
import mptt
from mptt.fields import TreeForeignKey
from django.contrib.auth.models import Group

# add a parent foreign key
TreeForeignKey(Group, blank=True, null=True, db_index=True).contribute_to_class(Group, 'parent')

mptt.register(Group, order_insertion_by=['name'])

在运行初始迁移时,我收到消息说四个字段即。由MPTTModel在现有Group模型上添加的level,lft,rght,tree_id需要默认值。所有这些都是PositiveIntegerField,我想知道在不破坏数据库的情况下我能提供的有效默认值是什么

1 个答案:

答案 0 :(得分:-1)

TreeForeignKey(Group, blank=True, null=True, db_index=True).contribute_to_class(Group, 'parent')
PositiveIntegerField(default=0, editable=False, db_index=True).contribute_to_class(Group, 'level')
PositiveIntegerField(default=0, editable=False, db_index=True).contribute_to_class(Group, 'lft')
PositiveIntegerField(default=0, editable=False, db_index=True).contribute_to_class(Group, 'rght')
PositiveIntegerField(default=0, editable=False, db_index=True).contribute_to_class(Group, 'tree_id')
mptt.register(Group,  order_insertion_by=['name'])