django:数据迁移权限 [英] django: data migrate permissions
问题描述
ContentType不可用
。 快速研究我发现
我甚至尝试使用 update_all_contenttypes( )
从django.contrib.contenttypes.management导入update_all_contenttypes
的导致迁移加载与固定装置不一致的数据。
在Django中迁移权限数据的最佳方式是什么?
p>有两种解决方法:
1)丑陋的方式:
运行 manage.py migration auth
在您想要的迁移之前
2)推荐方法:
from django.contrib.auth.management import create_permissions
def add_permissions(apps,schema_editor):
apps.models_module = True
create_permissions(apps,verbosity = 0)
apps.models_module =无
#其余的代码在这里....
I have a bunch of new permissions which I need to migrate. I tried doing it through data migration but complains about ContentType not being available
.
Doing quick research I found out that ContentType
table is populated after all the migrations applied.
I even tried using update_all_contenttypes()
from from django.contrib.contenttypes.management import update_all_contenttypes
which causes migration to load data which is not consistent to the fixture.
What is the best way to migrate permission data in Django?
There are 2 ways to solve this:
1) The ugly way:
Run manage.py migrate auth
before your wanted migration
2) Recommended way:
from django.contrib.auth.management import create_permissions
def add_permissions(apps, schema_editor):
apps.models_module = True
create_permissions(apps, verbosity=0)
apps.models_module = None
# rest of code here....
这篇关于django:数据迁移权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!