Django migrations 如何将django mptt重建添加到迁移中?
我已经将django mptt添加到现有数据库中,并创建了新的迁移 迁移过程被要求提供Django migrations 如何将django mptt重建添加到迁移中?,django-migrations,django-mptt,Django Migrations,Django Mptt,我已经将django mptt添加到现有数据库中,并创建了新的迁移 迁移过程被要求提供级别、左侧、右侧等字段的默认值,但未将模型。重建操作添加到迁移文件中 如何手动将重建操作添加到迁移文件?请尝试以下操作: from __future__ import unicode_literals from django.db import migrations from mptt import register, managers def rebuild_tree(apps, schema_edito
级别
、左侧
、右侧
等字段的默认值,但未将模型。重建
操作添加到迁移文件中
如何手动将重建操作添加到迁移文件?请尝试以下操作:
from __future__ import unicode_literals
from django.db import migrations
from mptt import register, managers
def rebuild_tree(apps, schema_editor):
YourMPTTModel = apps.get_model('your_app', 'YourMPTTModel')
manager = managers.TreeManager()
manager.model = YourMPTTModel
register(YourMPTTModel)
manager.contribute_to_class(YourMPTTModel, 'objects')
manager.rebuild()
class Migration(migrations.Migration):
operations = [
migrations.RunPython(
rebuild_tree
)
]