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!

musashiXXX
  • 4,192
  • 4
  • 22
  • 24

1 Answers1

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
Chris Pratt
  • 232,153
  • 36
  • 385
  • 444
  • 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".` – musashiXXX Jul 27 '11 at 17:53
  • 1
    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!! – musashiXXX Jul 27 '11 at 18:16