Skip to main content
 首页 » 编程设计

python之Django:应用程序标签不是唯一的

2025年05月04日34虾米姐

我一直在研究 Django 中的重复标签问题,来自 this answer我已将以下文件添加到我的“工作”项目文件夹中:

jobs/apps.py

# jobs/apps.py 
 
from django.apps import AppConfig 
 
class JobsConfig(AppConfig): 
    name = 'jobs' 
    verbose_name = "jobs2" 

jobs/init.py

# jobs/__init__.py 
 
default_app_config = 'jobs.apps.JobsConfig' 

这并没有多大帮助,我在尝试 syncdb 时仍然遇到错误:

"duplicates: %s" % app_config.label) 
django.core.exceptions.ImproperlyConfigured: Application labels aren't unique, duplicates: jobs 

此外,从“name = 'jobs'”更改为“name = 'jobs2'”只会给我错误:

ImportError: No module named jobs2 

文件结构

/opt/Webapp 
    ├── userfiles 
    ├── templates 
    │   └── admin 
    │       └── base.html 
    ├── static 
    │   ├── admin_tools 
    │   │   ├── images 
    │   │   │   └── apto.gif 
    │   │   └── css 
    │   │       └── theming.css 
    │   └── admin 
    │       └── css 
    │           └── base.css 
    ├── smartrecruitment 
    │   ├── wsgi.py 
    │   ├── urls.py 
    │   ├── settings.pyc 
    │   ├── settings.py 
    │   ├── __init__.pyc 
    │   └── __init__.py 
    ├── requirements.txt 
    ├── manage.py 
    ├── jobs 
    │   ├── views.py 
    │   ├── urls.py 
    │   ├── tests.py 
    │   ├── testhelpers.py 
    │   ├── templates 
    │   │   └── jobs 
    │   │       ├── test.html 
    │   │       ├── success.html 
    │   │       ├── registration.html 
    │   │       ├── registrationcomplete.html 
    │   │       └── application.html 
    │   ├── tables.py 
    │   ├── static 
    │   │   └── jobs 
    │   │       ├── styles 
    │   │       │   ├── index.css 
    │   │       │   ├── hide_admin_original.css 
    │   │       │   └── application.css 
    │   │       ├── style.css 
    │   │       └── images 
    │   │           └── apto.gif 
    │   ├── models.py 
    │   ├── migrations 
    │   │   ├── __init__.py 
    │   │   ├── 0002_auto__del_field_registrant_name__add_field_registrant_first_name__add_.py 
    │   │   └── 0001_initial.py 
    │   ├── lists.py 
    │   ├── __init__.pyc 
    │   ├── __init__.py 
    │   ├── forms.py 
    │   ├── apps.pyc 
    │   ├── apps.py 
    │   └── admin.py 
    ├── fileuploads 
    │   ├── tests.py 
    │   ├── templates 
    │   │   └── fileuploads 
    │   │       ├── index.html 
    │   │       ├── details.html 
    │   │       ├── base.html 
    │   │       └── add.html 
    │   ├── models.pyc 
    │   ├── models.py 
    │   ├── __init__.pyc 
    │   ├── __init__.py 
    │   ├── forms.pyc 
    │   ├── forms.py 
    │   ├── context_processors.py 
    │   └── admin.pyc 
    ├── dashboard.pyc 
    └── dashboard.py 

请您参考如下方法:

您的 jobs 应用中混合了旧式(south:0002_auto_del ...)和新式(django:0001_initial)迁移。最简单的解决方法是删除所有编号的迁移 rm jobs/migrations/0???_*.py* 并通过运行 manage.py makemigrations

重新创建迁移