背景
我正在使用PostgreSQL。
我想立即填充
auth.groups
和
auth.group_permissions
表,在我的项目第一次迁移后。
所以,在我按照我想要的方式设置好这些桌子后,我通过跑步来扔掉它们
python manage.py dumpdata auth.groups auth.group_permissions > core/fixtures/initial_data.json
生成的文件如下
[
{
"model": "auth.group",
"pk": 1,
"fields": {
"name": "Admin",
"permissions": [
29,
31,
32,
33,
34,
35,
36
]
}
},
{
"model": "auth.group",
"pk": 2,
"fields": {
"name": "Operators",
"permissions": [
42,
43,
44,
39,
40
]
}
},
{
"model": "auth.group_permissions",
"pk": 12,
"fields": {
"group": 1,
"permission": 32
}
},
{
"model": "auth.group_permissions",
"pk": 13,
"fields": {
"group": 1,
"permission": 33
}
},
{
"model": "auth.group_permissions",
"pk": 14,
"fields": {
"group": 1,
"permission": 34
}
},
{
"model": "auth.group_permissions",
"pk": 15,
"fields": {
"group": 1,
"permission": 35
}
},
{
"model": "auth.group_permissions",
"pk": 16,
"fields": {
"group": 1,
"permission": 36
}
},
{
"model": "auth.group_permissions",
"pk": 17,
"fields": {
"group": 1,
"permission": 29
}
},
{
"model": "auth.group_permissions",
"pk": 18,
"fields": {
"group": 1,
"permission": 31
}
},
{
"model": "auth.group_permissions",
"pk": 19,
"fields": {
"group": 2,
"permission": 39
}
},
{
"model": "auth.group_permissions",
"pk": 20,
"fields": {
"group": 2,
"permission": 40
}
},
{
"model": "auth.group_permissions",
"pk": 21,
"fields": {
"group": 2,
"permission": 42
}
},
{
"model": "auth.group_permissions",
"pk": 22,
"fields": {
"group": 2,
"permission": 43
}
},
{
"model": "auth.group_permissions",
"pk": 23,
"fields": {
"group": 2,
"permission": 44
}
}
]
问题是
为了尝试这个方法,我删除并重新创建了我的数据库,这样它就完全新鲜了,在第一个数据库之后
migrate
命令,我运行
python manage.py loaddata initial_data.json
这里我得到了错误
django.db.utils。完整性错误:安装夹具'/home/uname/Workspace/project/core/ftures/initial_data.json'时出现问题:
无法加载身份验证。Group_permissions(pk=12):重复的键值违反了唯一约束“auth_Group_permissions_Group_id_permission_id_0cd325b0_uniq”
详细信息:密钥(group_id,permission_id)=(1,32)已存在。
这让我很困惑。当这两个表此时完全为空时,它怎么能抛出重复的键呢?我如何让它用这些初始数据填充这两个表?
谢谢