I have a custom User model and custom permissions. After a while, I found that there was a typo in the name
of a permission, so I decided to update it in the code that creates it, then I ran makemigrations
and migrate
. The problem is that name
did not change in the DB even though the migration was applied.
What is more interesting is that when I deleted my database and run migrations from the start, the names got updated even though the permission name
in the initial migration was different.
EXAMPLE:
The initial setup
CUSTOM_PERMISSIONS = (
('some_codename', 'some human readable description'),
('some_codename2', 'some human readable description with RORRE'),
)
class User(AbstractUser):
# custom logic
class Meta:
ordering = ('-pk',)
verbose_name = _('user')
verbose_name_plural = _('users')
default_permissions = tuple()
permissions = CUSTOM_PERMISSIONS
and the initial migration has…
options={
'verbose_name': 'user',
'verbose_name_plural': 'users',
'ordering': ('-pk',),
'permissions': (('some_codename', 'some human readable description'), ('some_codename2', 'some human readable description with RORRE')),
'default_permissions': (),
},
…in the migration…
later I update the names of all custom permissions
CUSTOM_PERMISSIONS = (
('some_codename', 'some NEW human readable description'),
('some_codename2', 'some human readable description without ERROR'),
)
and run makemigrations which gives me a migration with:
operations = [
migrations.AlterModelOptions(
name='user',
options={'default_permissions': (), 'ordering': ('-pk',), 'permissions': (('some_codename', 'some NEW human readable description'), ('some_codename2', 'some human readable description without ERROR')), 'verbose_name': 'user', 'verbose_name_plural': 'users'},
),
]
and I run migrate, but the description is the same as in the initial migration. I then rename the db.sqlite
file and do a new migrate
call and the custom permissions have the updated values.
EDIT:
It is good to note that this is the same with a different db (i.e. Postgres)
Is there a way to update custom permission names without making a custom migration to update the permissions table?