我正在看看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,我想知道在不破坏数据库的情况下我能提供的有效默认值是什么
答案 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'])