错误:django.db.migrations.exceptions.BadMigrationError: Migration 0011_add_relevant_permissions_to_admin_and_operators in app config has no Migration class
此错误体向我建议我没有将Migration类放入所提到的文件中,但是正如我在下面发布的那样,我文件的代码确实具有Migration类,并且继承自Migrations.Migration >
0011_add_relevant_permissions_to_admin_and_operators
迁移文件的
代码:
from django.db import migrations
from django.contrib.auth.models import Permission
class Migration(migrations.Migration):
dependencies=[
('openwisp_user', '0004_default_groups'),
('config', '0010_auto_20180106_1814'),
]
operations=[
migrations.RunPython(assignPerm),
]
def assignPerm(apps, schema_editor):
Group= apps.get_model('openwisp_user', 'Group')
admin = Group.objects.get(name="Administrator")
operator= Group.objects.get(name="Operator")
operators_and_admins_can_change=["device", "config", "template", "location", "floorplan",]
operators_read_only_admins_manage=["vpn", "ca", "certificate",]
manage_operations=["add", "change", "delete"]
for i in operators_and_admins_can_change:
for j in manage_operations:
admin.permissions.add(Permission.objects.get(codename="{}_{}".format(j,i)), bulk=True)
operator.permissions.add(Permission.objects.get(codename="{}_{}".format(j,i)), bulk=True)
for i in operators_read_only_admins_manage:
try:
permission=Permission.objects.get(codename="view_{}".format(i))
operator.permissions.add(permission, bulk=True)
except Permission.DoesNotExist:
pass
for j in manage_operations:
admin.permissions.add(Permissions.objects.get(codename="{}_{}".format(j,i)), bulk=True)