在 remove_stale_contenttypes 之后丢失了一些 wagtail 组权限 - 如何找回它们?

Lost some wagtail group permissions after remove_stale_contenttypes - how to get them back?

在我的 Django/Wagtail 项目中重构一些模型后,我有一些陈旧的内容类型,在 wagtail 搜索应用程序中触发错误。

这些错误可以通过 运行 contenttypes 管理命令修复:

./manage.py remove_stale_contenttypes

好的,我收到了有关将被删除的内容的警告,并且确实列出了一些组权限对象。不管怎样,remove_stale_contenttypes 成功了,鹡鸰搜索又回来了。

但现在缺少一些权限:例如“可以访问 wagtail 管理员”组权限完全缺失,即使对于新组实例也是如此。

如何取回默认权限(有些权限已通过 wagtail/admin/migration 迁移过一次)?理想情况下,我想恢复我的生产站点上的所有 "default" 权限...

下面的代码(在./manage.py shell命令行上运行)应该是:

from django.contrib.contenttypes.models import ContentType
from django.contrib.auth.models import Permission
wagtailadmin_content_type, created = ContentType.objects.get_or_create(app_label='wagtailadmin', model='admin')
admin_permission, created = Permission.objects.get_or_create(content_type=wagtailadmin_content_type, codename='access_admin', name='Can access Wagtail admin')

这是a bug specifically affecting the "Can access wagtail admin" permission type,应该不会影响其他权限。