【问题标题】:Django: Application labels aren't uniqueDjango:应用程序标签不是唯一的
【发布时间】:2014-12-05 12:02:14
【问题描述】:

我一直在处理 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

【问题讨论】:

  • 尝试用label替换verbose_namelabel = "jobs2"。我遇到了同样的问题,它对我有用。
  • 同样清理所有.*pyc,没有这个通常是行不通的。
  • 谢谢,我删除了所有 .pyc 文件,用标签重命名了 verbose_name 然后运行了一个同步数据库,但这仍然给出了错误..
  • name=jobs 中,jobs 是否是该模块的完整路径(来自源根目录)?
  • 请查看我在 /opt/Webapp 的文件夹结构

标签: python django django-models django-1.7


【解决方案1】:

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

【讨论】:

  • 这对我有用@ryuusenshi :)。我有同样的问题,它解决了我的一天;)。谢谢
  • 没问题 :) 我向 code.djangoproject.com 提交了一张票,以使错误消息更具描述性,应该在 1.8.6 中修复。
猜你喜欢
  • 2014-10-13
  • 2018-10-16
  • 2015-01-29
  • 1970-01-01
  • 2020-04-10
  • 2017-10-28
  • 2021-10-21
  • 2019-09-09
相关资源
最近更新 更多