[Solved] RuntimeError: Model class apps.users.models.UserProfile doesn’t declare an explicit app_label and isn’t in an application in INSTALLED_APPS.

The following is the project directory structure I built under the project. Apps contains all the applications.

So I added the package guide path of the project below to facilitate the package guide.
import os
import sys
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) sys.path.insert(0, os.path.join(BASE_DIR, 'apps')) sys.path.insert(0, os.path.join(BASE_DIR, 'extra_apps'))

After investigation, it was found that the reason for this error was because the code was written like this when I imported the package:
from apps.users.models import BaseModel
from apps.courses.models import Course

So after I removed the apps, there was no error:
from users.models import BaseModel
from courses.models import Course

Summary: I personally think that the reason for this error is that we have added these two guide package paths. Every time the project guides the package, it will start from these guide package paths, and then start to find it. The first thing is to find the apps folder under these guide package paths. It is not found, so it starts to report such an error.

Similar Posts:

Leave a Reply

Your email address will not be published. Required fields are marked *