Prevent Django from re-creating default permissions

1.5k Views Asked by At

Is there a way I can remove all the permission that Django creates by default and prevent it from creating them again?

Currently I have a migration that runs a Permission.objects.all().delete() and I also have added default_permissions = () to the Meta class of all my models, and yet once I run the migration, the permissions disappear for a second, and then Django recreates them (I know it's a genuine recreation because the ID of each permission increases each time I run the migration).

So, is there a way I can completely disable automatic permission creation? Note that I'm saying disable creation, not hiding permissions (which I already know how to do).

1

There are 1 best solutions below

0
On

Have you looked into creating an app that has a post_migrate signal to do this?

I understand that all of the auth app's permission creating code happens when it calls its post_migrate function. See here and here

It should be the case that default_permissions = () should prevent creating permissions for the models you specify that in its Meta class, however since you can't do that on third party or django installed apps, you're left with those permissions in your DB till your new clean up post_migrate signal comes along and cleans them up.

Hope that helps