93

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?

John Carter
  • 53,924
  • 26
  • 111
  • 144

21 Answers21

114

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

John Carter
  • 53,924
  • 26
  • 111
  • 144
  • 2
    Questioner didn't accept his own answer, but it is correct. Once you do this, you place 'full.python.path.to.your.app.foo.apps.FooConfig' into your `INSTALLED_APPS` and everything works as expected. – Brett Sep 13 '14 at 23:04
  • 2
    Just wanted to mention, once you add the label run the migration like this: python manage.py makemigrations my.foo – Diego Sarmiento Sep 22 '16 at 22:50
  • 2
    Does this work for apps with existing database tables? I get a "dependencies reference nonexistent parent node" error when I make migrations after making these changes. – Andrew Schmitt Apr 05 '17 at 20:26
  • 1
    @John_Carter What's a `'full.python.path.to.your.app.foo'` normally look like? Does it involve `os.path`? Is it from the project root? – Gabe Rogan May 01 '17 at 20:36
  • @GabeRogan No, it'll be the python import path (so . separated, not / ) – John Carter May 02 '17 at 01:54
  • 2
    From my observation it's better to avoid dots in label name. The problem was with: AUTH_USER_MODEL = 'apps.auth.User' (won't work). Changing the label name and AUTH_USER_MODEL to 'apps_auth.User' solved the problem. – Mcmil May 01 '18 at 10:15
  • Shouldn't the label be `my_foo` rather than `my.foo`? I have a similar issue where `my.foo` didn't work but `my_foo` did – user8758206 Aug 02 '21 at 19:12
99

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.

Julia Tamsma
  • 15
  • 1
  • 4
yasirnazir
  • 1,133
  • 7
  • 12
24

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.

David Wolf
  • 1,400
  • 1
  • 9
  • 18
Sean
  • 259
  • 2
  • 2
14

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

М.Б.
  • 1,308
  • 17
  • 20
6

enter image description here 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!!

Pengyy
  • 37,383
  • 15
  • 83
  • 73
5

please check if anything is duplicated in INSTALLED_APPS of settings.py

Ankush Sahu
  • 578
  • 7
  • 13
3

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 paths).

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).

Dan Swain
  • 2,910
  • 1
  • 16
  • 36
gdoumenc
  • 589
  • 7
  • 10
3

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.

Leo
  • 449
  • 6
  • 5
3

In previous answer 'django.contrib.foo', was mentioned, but basically adding any app twice can cause this error just delete one (Django 3.0)

for me it was in settings.py

INSTALLED_APPS = [
  ...
  'accounts.apps.AccountsConfig',
  'accounts.apps.AccountsConfig',
  ...
]

just delete one of them

sogu
  • 2,738
  • 5
  • 31
  • 90
3

Basically this problem has been created due to duplication of name of installed app in the settings:

This is how I resolved the problem. In settings.py file:

  • Check the install app in the setting.py if the install app are duplicate

  • Error shown due to duplication of app name

  • Remove the duplicate name in the install file

  • After problem is resolved, you will see interface in your screen

For this I have created application name as polls instead of foo

Kols
  • 3,641
  • 2
  • 34
  • 42
2

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

2

Need to check in two file

1- apps.py

code something like

from django.apps import AppConfig
from django.utils.translation import ugettext_lazy as _
class ModuleConfig(AppConfig):
    name = "ocb.module_name"
    verbose_name = _("Module Name")

2 - init.py code something like

default_app_config = "ocb.users.apps.ModuleConfig"

default_app_config is pointed to your apps.py's class name

Saurabh Chandra Patel
  • 12,712
  • 6
  • 88
  • 78
1

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

CodeToLife
  • 3,672
  • 2
  • 41
  • 29
1

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.

Laban
  • 2,304
  • 1
  • 14
  • 15
0

From my experience, this exception was masking the real error. To see the real error (which in my case was an uninstalled python package) comment out the following in django/apps/registry.py:

if app_config.label in self.app_configs:
    # raise ImproperlyConfigured(
    #     "Application labels aren't unique, "
    #     "duplicates: %s" % app_config.label)
    pass
DannyMoshe
  • 6,023
  • 4
  • 31
  • 53
0

Check for duplicates in INSTALLED_APPS inside the settings.py...If so remove one of it and rerun the command

Rakesh Gombi
  • 322
  • 1
  • 3
  • 10
  • 1
    This is the same solution as in [this other answer](https://stackoverflow.com/a/63862307/2227743). – Eric Aya Jul 24 '21 at 14:15
0

I had Django==3.2.9 when tried to test my existing Django app on a new environment. I had this exact issue and fixed it by downgrading to Django==3.1.13.

There seems to be an update to applications, check the Django 3.2 documentation for detailed information.

rockikz
  • 586
  • 1
  • 6
  • 17
0

This error occurs because of duplication in your INSTALLED_APPS in settings.py file which is inside your project.

0

For me, the problem was that I had copy-pasted entire app instead of creating it using command line. So, the app name in the apps.py file was same for 2 apps. After I corrected it, the problem was gone.

0

I was able to solve the same problem. As I understand it, this happened due to the fact that I performed an incorrect copy of the folder when creating static files. In general, try to find all duplicates in the code. Look in the urls

-1

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