How to restore deleted permissions on a model in a django project

64 Views Asked by At

I want to create a new group and add permissions to the group called "mod". The permission I want to give to this group is Can add, Can Change, Can Delete, and Can View. After I added all the permissions in the "Post" model for the group , I wanted to remove a permission from the group but accidentally deleted the permission itself. How do I restore deleted permissions?

1

There are 1 best solutions below

0
Abdul Aziz Barkat On

Although this is not really clear from the documentation what the post_migrate signal mentioned there actually does is that it creates any missing permissions for your models that would otherwise be created automatically.

This means if you accidentally delete a permission all you need to do to restore it is to run the following to restore it:

python manage.py migrate

Note: This will only create / restore the permission itself, it won't restore any relations you might have created between the permission and various groups, etc. that got deleted when you deleted the permission, you'd need to restore those relations manually.