Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ContentType doesn't declare an explicit app_label

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 [email protected]

   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.

like image 265
eli Avatar asked Mar 15 '17 13:03

eli


2 Answers

Try running the following commands:

python manage.py makemigrations 
python manage.py migrate

This solved the issue on my side.

like image 165
Kirumosama Avatar answered Sep 23 '22 05:09

Kirumosama


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.

like image 36
eli Avatar answered Sep 21 '22 05:09

eli