I am having major problems getting a Django app installed on an Ubuntu machine running Django 1.10.6.
I am used to using an older version of Django and now I cannot get my webapp to install. Here is the situation:
I have a Django project called myproject. The file structure is:
(BASEDIR)/manage.py
(BASEDIR)/mycommon/ # I will discuss mycommon below
(BASEDIR)/myproject/
(BASEDIR)/myproject/settings.py
(BASEDIR)/myproject/urls.py
(BASEDIR)/myproject/views.py
(BASEDIR)/myproject/wsgi.py
(BASEDIR)/myproject/models/
(BASEDIR)/myproject/models/__init__.py
(BASEDIR)/myproject/models/models.py
It turns out that for this project I need to put my models in a common package because there is another python application (using Twisted that bootstraps Django) that needs to access these models. I will call this package "mycommon". So my "real" models are here:
(BASEDIR)/mycommon/
(BASEDIR)/mycommon/utils.py
(BASEDIR)/mycommon/models/
(BASEDIR)/mycommon/models/__init__.py
(BASEDIR)/mycommon/models/models.py
So the Django settings file is in (BASEDIR)/myproject/settings.py and the INSTALLED_APPS parameter is set to this:
INSTALLED_APPS = (
'myproject.models',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.admin',
)
Finally, note that myproject/models/models.py is very simple, since it just uses the mycommon models:
from django.db import models
from mycommon.models.models import *
So far so good, this is a structure that works fine on older Django versions. Anyway, I start with an empty MYSQL database (created but empty) and now I go back to (BASEDIR) and run this:
python manage.py makemigrations mycommon.models
Unfortunately I get an error like this:
RuntimeError: Model class mycommon.models.models.SomeModel doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS.
So what am I doing wrong?
In INSTALLED_APPS you should have only 'myproject', without '.models'.
But since you are using Django 1.10, it will be cleaner if you create your mycommon app via manage.py startapp mycommon. This will create, well, some files, but you should move your models to mycommon/models.py. Note the mycommon/apps.py. You don't have to touch this file, only include it in the INSTALLED_APPS list: 'mycommon.apps.MycommonConfig'. This way the migrations framework will discover your models automatically.
Finally, remove myproject/models, since myproject holds the project configuration.