Migrating django admin auth.groups and users to a new database using fixtures
Asked Answered
B

1

8

Here's the scenario:

I'm using django's admin interface and I would like to be able to load users and groups via fixtures (if this is possible.) I'm able to dump users/groups like so:

manage.py dumpdata auth auth.group > usersandgroups.json

But upon loading the data in a brand new database...

manage.py loaddata <appname>/fixtures/usersandgroups.json

I get all sorts of errors having to do with foreign keys and such. Here's an example of one:

django.db.utils.IntegrityError: insert or update on table "auth_permission" violates foreign key constraint "content_type_id_refs_id_728de91f"

DETAIL: Key (content_type_id)=(37) is not present in table "django_content_type".

I'd really appreciate it if anyone could point me in the right direction. Thanks in advance!

Bod answered 27/7, 2011 at 13:6 Comment(0)
S
16

You're including more than just user and groups in your dump -- namely, permissions as well. You're getting a conflict because of the permissions. Since you don't need those, just get rid of them from your fixture.

manage.py dumpdata auth.User auth.Group > usersandgroups.json
Sites answered 27/7, 2011 at 15:7 Comment(2)
No luck! I'm getting similar errors when doing it that way: django.db.utils.IntegrityError: insert or update on table "auth_user_user_permissions" violates foreign key constraint "auth_user_user_permissions_permission_id_fkey" DETAIL: Key (permission_id)=(111) is not present in table "auth_permission".Bod
Actually you did help point me in the right direction! I cleared out all permissions from my "prototype" database (via django's admin interface); exported the data in the manner shown above; then loaded it in a new database without error. Thanks!!Bod

© 2022 - 2024 — McMap. All rights reserved.