1

Whenever I try to run makemigrations or runserver, I get this error:

RuntimeError: Model class django.contrib.contenttypes.models.ContentType doesn't declare an explicit app_label and       
isn't in an application in `INSTALLED_APPS`.

HOWEVER: Here it is in INSTALLED_APPS--

WSGI_APPLICATION = 'mysite.wsgi.application'
import django
django.setup()

# Application definition

INSTALLED_APPS = [
                    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',

    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django_comments',
    'django_comments_xtd',
    'django.contrib.sites',
    'accounts.apps.AccountsConfig',
    'posts.apps.PostsConfig',

    'category',
    #'vote',
    'tinymce',
    'django_wysiwyg',
    'follow',

    'djrichtextfield',
    'ckeditor',
    #'likes',
    'secretballot',

    'hitcount',
    #'pinax',
    'pinax.likes',

    #'pinax',
    #'pinax_theme_bootstrap',
    #'bootstrapform',

    #'voting',
    'actstream',


]

What could be causing this? It's explicitly stated in Installed_Apps, as you can see.

Tom Higgins
  • 99
  • 2
  • 10

4 Answers4

1

If you registered your django app in INSTALLED_APPS then just make sure you are selecting the right settings, maybe you forgot to set some environment variable

Ghaleb Khaled
  • 180
  • 1
  • 10
0

a friend and I just solved this issue, after read and read answers and try, none of those answers were helpfull (no in 100% at least), just try in your users\apps.py:

for me:

class UsersConfig(AppConfig):

name = "opercat_api.users"
verbose_name = _("Users")

for you guys:

class UsersConfig(AppConfig):

name = "myapp.users"
verbose_name = _("Users")

Then in your Myapp\apps.py:

for me:

class ExcepcionesConfig(AppConfig):

name = 'opercat_api.excepciones'
verbose_name = 'Excepciones'

for you guys:

Class MyappnameConfig(AppConfig):

name = 'myproject.myappname'
verbose_name = 'Myappname'

And of course, don't forget check the INSTALLED_APPS within your (settings/base).py

I really hope this answer along with the others may help you guys

ArtyomFSB
  • 1
  • 2
0

I've run into the same error, and it really took me quite a while to figure it out. This is a very non-obvious error, so the steps you took before getting this error really matter.

For me, it happened while refactoring my app, after changing my User model to inherit from AbstractUser, not from models.Model, and pointing AUTH_USER_MODEL to my custom model with custom db table. Whenever I tried to run server or make migrations, this error popped up. It really got me stuck for several days. I tried almost everything suggested here or anywhere else on Stack that I could find, except legacy and DRF issues, for I was using Django 4.1. Nothing helped, nothing worked, like nothing at all. I was beginning to contemplate rewriting my app from scratch, though it would've been a tedious task. However, this answer with some insight to this error and this answer really got me thinking right. This error is sure not an over-informative one, it can happen due to lots of different things, so it's useful to look back at the steps you took before this error happened.

In my case this error was preceded by another error. After I set AUTH_USER_MODEL to my custom model, I got django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet. I did the suggested

import django 
django.setup()

in the settings.py, and that's where I got the dreadful ...ContentType doesn't declare an explicit app_label... error.

The answer to this was that I've made quite a newbie mistake not quoting my custom model in AUTH_USER_MODEL. It was like:

AUTH_USER_MODEL = my_app_name.models.User

Of course I had to import that to settings.py for it to work. However, as I understand it now, import happened before this app was declared in INSTALLED_APPS, that's why Django showed django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet. And then, instead of thinking on why this is happening, I forcefully got Django working with

import django 
django.setup()

just to crash it for good. I guess Django was like

Hey dude it's a mistake, it won't work, but OK if you insist I'll take it, oh gotcha here's another one for you, I TOLD YA it won't work ha-ha now have fun.

Changing my AUTH_USER_MODEL to

AUTH_USER_MODEL = 'my_app_name.User'

as suggested here, really did the trick for me. Pay attention to set it just like this, without models, only your app name and the name of class in your models.

Of course, I've instantly got Django complaining again, but this time it was about manager not being available, which is because I haven't yet put it in my custom model=)

TL:DR

We kinda got used to straightforwardly google the last error we got, but this particular error can happen due to a wide variety of reasons, and googling it alone might be akin to reading tea-leaves. It may be way more useful to sit back, relax a bit, and take a look at the steps preceding this error. If you, like me, faced the Apps aren't loaded yet error before this one, just check that you quoted the value of AUTH_USER_MODEL, if you declared one in your settings.py file (as shown here), and also check that you don't have any code in your settings.py, that imports things from other apps (as suggested here). Importing things from your app to settings.py of this app won't work, because import happens before your app has been declared in INSTALLED_APPS. Forcing it to work with

import django 
django.setup()

will crash Django for good and send you wandering across the Stack wondering what went wrong.

Hope it'll help other people out there struggling to learn Django!

Odyvia42
  • 3
  • 2
-2

I got it working by downgrading Django to 1.8. There is some problem with 1.9 I guess!

Aditya
  • 352
  • 1
  • 12