django: adding custom permissions stopped working

爱⌒轻易说出口 提交于 2020-01-16 08:33:10

问题


I have a django project with multiple apps. In one of the apps when I add custom permissions to any model and run makemigration, the migration-file to add the permission is created. When I apply the migration I get no error messages but the permission isn't added to the auth_permission table.

class Meta:
    app_label = 'my_app'

    permissions = (
        ('assign_work_type', 'Assign work type'),
    )

The migration completes without errors

I have tried doing the same in other apps and that works. I have also tried adding a column to the current app and that works as well. Anyone got any idea what it could be? I am running django 1.11.26

UPDATE

Here is the content of the migration file

# -*- coding: utf-8 -*-
# Generated by Django 1.11.26 on 2019-11-25 11:13
from __future__ import unicode_literals

from django.db import migrations


class Migration(migrations.Migration):

    dependencies = [
        ('timereport', '0143_auto_20191122_1754'),
    ]

    operations = [
        migrations.AlterModelOptions(
            name='worktype',
            options={'permissions': (('assign_work_type', 'Assign work type'),)},
        ),
    ]


回答1:


After quite some investigation I found that the affected app was missing the models_module, i.e. the "models.py" file. I have all my models in a /model/ directory and a while back I deleted the models.py file thinking it was of no use.

Adding the models.py file back solved the issue



来源:https://stackoverflow.com/questions/59007757/django-adding-custom-permissions-stopped-working

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!