3

I've built an application that I want to move from my development server to my production server. In this application I have defined 3 custom groups in auth.group and each of those have specific permissions.

I've tried to dump the data from auth.group - it seems to include permissions ids as well. The problem is, those IDs don't match between my development environment and the production environment. It also seems there is a content_type_id in auth.permission that I don't know how it relates.

My question is, is there a way using dumpdata or something else, to migrate Groups and all of the related permissions for my application? I don't have a problem importing multiple fixtures on the production server, but I do want all of the groups to be set up without having to go through the UI and selecting the appropriate permissions for each group.

NewGuy
  • 3,273
  • 7
  • 43
  • 61

1 Answers1

5

django.contrib.auth depends on django.contrib.contenttypes because auth.models.Permission.content_type is a ForeignKey(ContentType).

Solution: add ContentType in your data dump, ie. dumpdata with the following arguments: auth.group contenttypes.contenttype auth.permission

jpic
  • 32,891
  • 5
  • 112
  • 113
  • Ok. If I do this, I receive `pk` values for the contenttypes. In my other default data fixtures, I clear the primary keys since they do not matter for those specific models. In this instance, though, that will not work because the permissions appear to relate back to a contenttype and a group relates back to a permission(s). If I import the datadump directly, I receive primary key violations because I have some of these primary keys in place already. How can I make this generic enough that I can import it to a system that has data already? – NewGuy Sep 10 '12 at 15:36
  • "If I import the datadump directly, I receive primary key violations because I have some of these primary keys in place already." that's unlikely: django does insert or update for fixtures. I noticed that the order of arguments in my answer could be improved.. Did you try in this order too (ctypes before permission) ? But I don't think that matters either because Django tries to disable these kind of constraints that could block fixture imports (ie. FK to self). It would be easier if you pasted tracebacks, data dumps etc etc ... – jpic Sep 10 '12 at 15:47