I'm getting this error and I've been trying to fix it for many hours, it came up once I separated my models.py into a directory with multiple files.
This is the current structure of my project. I have omitted many files, but these are the relevant ones:
- Project_folder
- academy
- app1
- app2
- manage.py
- models
- _ _ init _ _.py
- content.py
- session.py
- app3
- config
- static
- academy
Before, I had all my models in a single file inside app2, called models.py. However, as the file started to grow too large, I separated each of the models into different categories. Also, in __init__.py
I imported these elements:
from academy.app2.models.content import *
from academy.app2.models.session import *
Now, when I try to make migrations with python manage.py makemigrations app2
, as usual, I'm getting this error:
RuntimeError: Model class app2.models.content.Reward doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS.
When I searched for this error, I came across this answer, however, when I add the Meta Class declarating the app_label, I get this error:
RuntimeError: Conflicting 'reward' models in application 'app2': <class 'academy.app2.models.content.Reward'> and <class 'app2.models.content.Reward'>.
This is my Config file for app2:
class App2Config(AppConfig):
name = 'academy.app2'
This is my INSTALLED_APPS:
INSTALLED_APPS = [
...
'academy.app2.apps.App2Config',
...
]
This error did not occur when I had a single models.py file, but when I separated it into separate files. I also tried to create an additional base model, and define in that model the Meta Class, inheriting in the rest of the models, without success.