I am new to Django and working on a project that needs a custom user. I created folders for models, views, URLs, and serializers. Each feature has its own file in these folders.
Everything works fine until I rename models.py file to users_model.py or move it to the models folder that I created.
When I makemigrations the following error appears:
django.core.exceptions.ImproperlyConfigured: AUTH_USER_MODEL refers to model 'app.AppUser' that has not been installed
backend/
βββ config/
β βββ __pycache__/
β βββ __init__.py
β βββ asgi.py
β βββ settings.py
β βββ urls.py
β βββ wsgi.py
βββ app/
β βββ __pycache__/
β βββ migrations/
β βββ __init__.py
β βββ admin.py
β βββ apps.py
β βββ models
β β βββ users_model.py
β β βββ model_for_featur_1
β β βββ model_for_featur_2
β βββ serializer
β β βββ users_serializer.py
β β βββ serialize_for_featur_1
β β βββ serialize_for_featur_2
β βββ views
β β βββ users_view.py
β β βββ view_for_featur_1
β β βββ view_for_featur_2
β βββ urls
β β βββ url_for_featur_1
β β βββ url_for_featur_2
βββ manage.py
My code:
users_model.py
class AppUser(AbstractBaseUser):
.
.
.
class MyUserManager(BaseUserManager):
def create_user(self, email, username, password):
.
.
def create_superuser(self, email, username, password):
.
.
Admin.py
.
.
admin.site.register(AppUser)
sittings.py
INSTALLED_APPS = [
.
.
"app",
]
AUTH_USER_MODEL = "app.AppUser"
I tried AUTH_USER_MODEL = "app.models.users_model.AppUser"
ValueError: Invalid model reference 'app.models.users_model.AppUser'. String model references must be of the form 'app_label.ModelName'.
I tried AUTH_USER_MODEL = "app.models.AppUser"
ValueError: Invalid model reference 'app.models.AppUser'. String model references must be of the form 'app_label.ModelName'.
>Solution :
you need to create __init__.py file in models folder and it looks like that:
## __init__.py
from .user import AppUser