Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 748
John Carter Avatar asked Jun 20 '14 03:06

John Carter


1 Answers

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

like image 159
John Carter Avatar answered Oct 02 '22 12:10

John Carter