How to resolve “django.core.exceptions.ImproperlyConfigured: Application labels aren't unique, duplicates: foo” in Django 1.7?

跟風遠走 提交于 2019-11-26 06:37:05

问题


On upgrading to Django 1.7 I\'m getting the following error message from ./manage.py

$ ./manage.py 
Traceback (most recent call last):
  File \"./manage.py\", line 16, in <module>
    execute_from_command_line(sys.argv)
  File \"/home/johnc/.virtualenvs/myproj-django1.7/local/lib/python2.7/site-packages/django/core/management/__init__.py\", line 427, in execute_from_command_line
    utility.execute()
  File \"/home/johnc/.virtualenvs/myproj-django1.7/local/lib/python2.7/site-packages/django/core/management/__init__.py\", line 391, in execute
    django.setup()
  File \"/home/johnc/.virtualenvs/myproj-django1.7/local/lib/python2.7/site-packages/django/__init__.py\", line 21, in setup
    apps.populate(settings.INSTALLED_APPS)
  File \"/home/johnc/.virtualenvs/myproj-django1.7/local/lib/python2.7/site-packages/django/apps/registry.py\", line 89, in populate
    \"duplicates: %s\" % app_config.label)
django.core.exceptions.ImproperlyConfigured: Application labels aren\'t unique, duplicates: foo

What\'s the problem and how do I resolve it?


回答1:


The problem is that with the changes to apps in Django 1.7, apps are required to have a unique label.

By default the app label is the package name, so if you've got a package with the same name as one of your app modules (foo in this case), you'll hit this error.

The solution is to override the default label for your app, and force this config to be loaded by adding it to __init__.py.

# foo/apps.py

from django.apps import AppConfig

class FooConfig(AppConfig):
    name = 'full.python.path.to.your.app.foo'
    label = 'my.foo'  # <-- this is the important line - change it to anything other than the default, which is the module name ('foo' in this case)

and

# foo/__init__.py

default_app_config = 'full.python.path.to.your.app.foo.apps.FooConfig'

See https://docs.djangoproject.com/en/1.7/ref/applications/#for-application-authors




回答2:


I found simple solution for this. In my case following line is added twice under INSTALLED_APPS,

'django.contrib.foo',

Removed one line fixes the issue for me.




回答3:


I had the same error - try this:

in INSTALLED_APPS, if you are including 'foo.apps.FooConfig', then Django already knows to include the foo app in the application, there is therefore no need to also include 'foo'. Having both 'foo' and 'foo.apps.FooConfig' under INSTALLED_APPS could be the source of your problem.




回答4:


As therefromhere said this is a new Django 1.7 feature which adds a kind of “app registry” where applications must be determined uniquely (and not only having different python pathes).

The name attribute is the python path (unique), but the label also should be unique. For example if you have an app named 'admin', then you have to define the name (name='python.path') and a label which must be also unique (label='my admin' or as said put the full python path which is always unique).




回答5:


Well, i created auth app, and i've included it in INSTALLED_APP like src.auth (because it's in src folder) and i got this error, because there is django.contrib.auth app also. So i renamed it like authentication and problem solved.




回答6:


I got the same problem. Here my app name was chat and in the settings.py , under installed apps i have written chat.apps.ChatConfig while i have already included the app name chat at the bottom. When i removed the chat.apps.ChatConfig mine problem was solved while migrations. This error may be due to the same instance that you might have defined you app name foo twice in the settings.py. I hope this works out!!


回答7:


in my case, in mysite settings.py , in INSTALLED_APPS array variable I put the name of the app twice by mistake.




回答8:


I had almost the same issue.

```File "/Users/apples/.local/share/virtualenvs/ecommerce-pOPGWC06/lib/python3.7/site-packages/django/apps/registry.py", line 95, in populate
"duplicates: %s" % app_config.label)

django.core.exceptions.ImproperlyConfigured: Application labels aren't unique, duplicates: auth```

I had installed Django.contrib.auth twice. I removed one and it worked well.




回答9:


Had same issue, read through the settings.py of the root folder, removed any INSTALLED APPS causing conflict... works fine. Will have to rename the apps names




回答10:


This exception may also be raised if the name of the AppConfig class itself matches the name of another class in the project. For example:

class MessagesConfig(AppConfig):
    name = 'mysite.messages'

and

class MessagesConfig(AppConfig):
    name = 'django.contrib.messages'

will also clash even though the name attributes are different for each configuration.




回答11:


In case if you have added your app name in settings.py example as shown in figure than IN settings.py Remove it and Try this worked for me. give it a try . This Worked Because settings.py assumes installing it twice and does not allow for migration




回答12:


If you want to back older version, command

pip install django==1.6.7


来源:https://stackoverflow.com/questions/24319558/how-to-resolve-django-core-exceptions-improperlyconfigured-application-labels

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