添加自定义权限停止工作

添加自定义权限停止工作

本文介绍了django:添加自定义权限停止工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含多个应用程序的django项目.在其中一个应用程序中,当我向任何模型添加自定义权限并运行makemigration时,就会创建要添加权限的迁移文件.当我应用迁移时,我没有收到任何错误消息,但是该权限未添加到auth_permission表中.

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

我尝试在其他应用程序中执行相同的操作,并且可以正常工作.我也尝试过在当前应用程序中添加一列,效果也不错.任何人都知道这可能是什么吗?我正在运行django 1.11.26

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

更新

这是迁移文件的内容

# -*- 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'),)},
        ),
    ]

推荐答案

经过一番调查后,我发现受影响的应用缺少了models_module,即"models.py"文件.我将所有模型都放在/model/目录中,不久前我删除了models.py文件,认为它没有用.

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.

重新添加models.py文件解决了该问题

Adding the models.py file back solved the issue

这篇关于django:添加自定义权限停止工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-02 00:41