Django 2.1.4: Permissions are not updated after migrations

175 views
Skip to first unread message

Yevgeny Bar Lev

unread,
Mar 17, 2019, 5:31:16 PM3/17/19
to Django users
Hello,
I have noticed that the available permissions list, which can be set to users/groups in the admin doesn't match my models. This happened after a few standard migrations, where some models were renamed, some deleted, and new models were added. The list is basically not updated, and represents a mixed state of the db, before and after the above migrations.

manage.py inspectdb show the CORRECT state of the database. 

I have tried to follow the following solution, which basically didn't do much.

from django.contrib.auth.management import create_permissions
from django.apps import apps

create_permissions(apps.get_app_config('my_app_name'))
I will appreciate your help.
Best,
Yevgeny.

Simon Charette

unread,
Mar 17, 2019, 7:20:20 PM3/17/19
to Django users
Hello Yevgeny,

I don't have magic solution to suggest to you given the current state of your
permission data after a few iterations but I just wanted to let you know that
it's a known issue[0] and a contributor is actively working on getting it fixed[1].

Cheers,
Simon

Yevgeny Bar Lev

unread,
Mar 17, 2019, 7:52:45 PM3/17/19
to django...@googlegroups.com
Thanks Simon. Is there some nonmagical solution? I mean, is it possible to fix some of the permissions manually without breaking stuff?

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/9c49dff1-c6b1-43e6-818d-f56ab761558d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Simon Charette

unread,
Mar 18, 2019, 4:37:22 AM3/18/19
to Django users
Hello Yevgeny,

I'd start by deleting your stale content types[0] which your permissions are attached
to. That should deal with deleted model case.

For the renames I suggest you drop into a shell and manually edit the Permission.name
of the misnamed instances.

Best,
Simon

Yevgeny Bar Lev

unread,
Mar 18, 2019, 8:35:55 AM3/18/19
to django...@googlegroups.com
Thanks Simon!
Two questions:
a) Would the following strategy work? delete all app permission and use, create_permissions to recreate them
b) How do I know to which db table a given permission points? Or does it point to a model?

Simon Charette

unread,
Mar 18, 2019, 1:52:27 PM3/18/19
to Django users
> Would the following strategy work? delete all app permission and use, create_permissions to recreate them

Yes, but that will delete all the user and group permissions as well; you'll have to reassign them.

> How do I know to which db table a given permission points? Or does it point to a model?

They point to models through the Permission.content_type foreign key; ContentType have an (app_label, model_name)
unique tuple.

Best,
Simon

Yevgeny Bar Lev

unread,
Mar 18, 2019, 2:00:06 PM3/18/19
to django...@googlegroups.com
Thanks a lot, Simon!
The delete and create sounds like the perfect solution in my case, since I don't have a lot of permissions assigned.
Will try it now on a test case.

Reply all
Reply to author
Forward
0 new messages