【发布时间】:2016-02-02 19:11:14
【问题描述】:
我想创建创建权限和组的数据迁移,以便我的其他开发人员可以运行迁移并设置所有内容。我能够创建迁移并正常运行它们,但现在运行测试时出现错误。
但如果我这样做:
from django.contrib.auth.models import Group
def add_operations_group(apps, schema_editor):
Group.objects.get_or_create(name='operations')
我明白了:
django.db.utils.OperationalError: no such table: auth_group
如果我这样做:
def add_operations_group(apps, schema_editor):
Group = apps.get_model("django.contrib.auth", "group")
Group.objects.get_or_create(name='operations')
我明白了:
LookupError: No installed app with label 'django.contrib.auth'
有没有办法做到这一点?或者是否有“Django 方式”来确保创建权限和组等内容?
【问题讨论】: