9

I am deploying a Django 1.10 project onto an Ubuntu server with Apache and mod_wsgi. I am getting the following 500 error which I can't solve:

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

installed_apps in settings.py:

INSTALLED_APPS = [
    'django.contrib.sites',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'dashboard',
]

wsgi.py:

sys.path.append('/home/x_dashboard/x_dashboard/')

activate_this = os.path.expanduser("/home/x_dashboard/.venv/bin/activate_this.py")
execfile(activate_this, dict(__file__=activate_this))

os.environ['PYTHON_EGG_CACHE'] = '/home/x_dashboard/x_dashboard/.python-egg'
os.environ['DJANGO_SETTINGS_MODULE'] = 'x_dashboard.settings'

import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()

Apache config:

<VirtualHost *:80>
   #ServerName example.com
   #ServerAlias www.example.com
   #ServerAdmin username@example.com

   DocumentRoot /home/x_dashboard/x_dashboard/

   #ErrorLog /var/www/html/example.com/logs/error.log
   #CustomLog /var/www/html/example.com/logs/access.log combined

   WSGIScriptAlias / /home/x_dashboard/x_dashboard/x_dashboard/wsgi_local.py

   #Alias /robots.txt /var/www/html/example.com/public_html/robots.txt
   #Alias /favicon.ico /var/www/html/example.com/public_html/favicon.ico
   #Alias /images /var/www/html/example.com/public_html/images
   Alias /static /var/www/x_dashboard/static

   <Directory /home/x_dashboard/x_dashboard/x_dashboard/>
     <Files wsgi.py>
     Order deny,allow
     Allow from all
     Require all granted
     </Files>
   </Directory>
</VirtualHost>

The Django documentation says that an app_label is required for models which do not belong to an app defined in installed_apps. However, 'django.contrib.contenttypes' is defined in installed_apps.

Any help appreciated.

eli
  • 4,636
  • 7
  • 25
  • 29

3 Answers3

5

Try running the following commands:

python manage.py makemigrations 
python manage.py migrate

This solved the issue on my side.

Adrian Mole
  • 49,934
  • 160
  • 51
  • 83
Kirumosama
  • 51
  • 1
  • 3
2

For anyone else struggling with this bug: I solved it by moving 'django.contrib.contenttypes', to the top of my installed_apps list in settings.py.

I also moved

import django
django.setup()

to after installed_apps. This thread was helpful.

Community
  • 1
  • 1
eli
  • 4,636
  • 7
  • 25
  • 29
1

Just make sure to set up your env var: DJANGO_SETTINGS_MODULE=project_dir.settings.local.

enter image description here

Mohammad Mahjoub
  • 417
  • 4
  • 12