Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django/Python "django.core.exceptions.ImproperlyConfigured: Cannot import 'contact'. Check that '...apps.contact.apps.ContactConfig.name' is correct"

Hopefully you all can give me a hand with this...

my work flow:

|.vscode:
|capstone_project_website:
|   -_pycache_:
|   -apps:
|       -_pycache_
|       -accounts:
|       -contact:    # app that is throwing errors
|           -_pycache_:
|          -migrations:
|          -_init_.py
|          -admin.py
|          -apps.py
|          -forms.py
|          -models.py
|          -test.py
|          -urls.py
|          -views.py 
|       -public:
|       -_init_.py
|   -templates: # all my .html 
|   -_init_.py
|   -asgi.py
|   -settings.py
|   -urls.py
|   -views.py
|   -wsgi.py
|requirements:
|scripts:
|static:
|.gitignore
|.python-version
|db-sqlite3
|docker-compose.yml
|Dockerfile
|Makefile #command I am running
|manage.py
|setup.cfg

my Installed apps in capstone_project_website/settings.py:

INSTALLED_APPS = [
"django.contrib.admin",
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sessions",
"django.contrib.messages",
"django.contrib.staticfiles",
"capstone_project_website.apps.accounts",
"capstone_project_website.apps.contact", ]

my capstone_project_website/apps/contact/apps.py:

from django.apps import AppConfig

class ContactConfig(AppConfig):
    name = "contact"

the command I am running is in my Makefile:

compose-start:
    docker-compose up --remove-orphans $(options)

When I run make compose-start I get this message from my Terminal:

make compose-start
docker-compose up --remove-orphans
Docker Compose is now in the Docker CLI, try `docker compose up`

Starting django-website_postgres_1 ... done
Starting django-website_db_migrate_1 ... done
Starting django-website_website_1    ... done

Attaching to django-website_postgres_1, django-website_db_migrate_1, django-website_website_1
db_migrate_1  | Traceback (most recent call last):
db_migrate_1  |   File "/usr/local/lib/python3.7/site-packages/django/apps/config.py", line 244, in create
db_migrate_1  |     app_module = import_module(app_name)
db_migrate_1  |   File "/usr/local/lib/python3.7/importlib/__init__.py", line 127, in import_module
db_migrate_1  |     return _bootstrap._gcd_import(name[level:], package, level)
db_migrate_1  |   File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
db_migrate_1  |   File "<frozen importlib._bootstrap>", line 983, in _find_and_load
db_migrate_1  |   File "<frozen importlib._bootstrap>", line 965, in _find_and_load_unlocked
db_migrate_1  | ModuleNotFoundError: No module named 'contact'
db_migrate_1  |
db_migrate_1  | During handling of the above exception, another exception occurred:
db_migrate_1  |
db_migrate_1  | Traceback (most recent call last):
db_migrate_1  |   File "manage.py", line 22, in <module>
db_migrate_1  |     main()
db_migrate_1  |   File "manage.py", line 18, in main
db_migrate_1  |     execute_from_command_line(sys.argv)
db_migrate_1  |   File "/usr/local/lib/python3.7/site-packages/django/core/management/__init__.py", line 419, in execute_from_command_line
db_migrate_1  |     utility.execute()
db_migrate_1  |   File "/usr/local/lib/python3.7/site-packages/django/core/management/__init__.py", line 395, in execute
db_migrate_1  |     django.setup()
db_migrate_1  |   File "/usr/local/lib/python3.7/site-packages/django/__init__.py", line 24, in setup
db_migrate_1  |     apps.populate(settings.INSTALLED_APPS)
db_migrate_1  |   File "/usr/local/lib/python3.7/site-packages/django/apps/registry.py", line 91, in populate
db_migrate_1  |     app_config = AppConfig.create(entry)
db_migrate_1  |   File "/usr/local/lib/python3.7/site-packages/django/apps/config.py", line 250, in create
db_migrate_1  |     app_config_class.__qualname__,
db_migrate_1  | django.core.exceptions.ImproperlyConfigured: Cannot import 'contact'. Check that 'capstone_project_website.apps.contact.apps.ContactConfig.name' is correct.
postgres_1    |
postgres_1    | PostgreSQL Database directory appears to contain a database; Skipping initialization
postgres_1    |
postgres_1    | 2021-05-02 14:17:44.105 UTC [1] LOG:  starting PostgreSQL 13.2 (Debian 13.2-1.pgdg100+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 8.3.0-6) 8.3.0, 64-bit
postgres_1    | 2021-05-02 14:17:44.106 UTC [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432
postgres_1    | 2021-05-02 14:17:44.106 UTC [1] LOG:  listening on IPv6 address "::", port 5432
postgres_1    | 2021-05-02 14:17:44.113 UTC [1] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
postgres_1    | 2021-05-02 14:17:44.121 UTC [28] LOG:  database system was shut down at 2021-05-02 14:17:17 UTC
django-website_db_migrate_1 exited with code 1
postgres_1    | 2021-05-02 14:17:44.129 UTC [1] LOG:  database system is ready to accept connections
website_1     | Watching for file changes with StatReloader
^CGracefully stopping... (press Ctrl+C again to force)
Stopping django-website_website_1    ... done
Stopping django-website_postgres_1   ... done

I know I put a lot of my work flow in, but I am wondering if I am setting it up incorrectly. I have run into this problem before when trying to makemigrations on my accounts app. the answer to that one seemed to work. the answer was to change the name in capstone_project_website/apps/accounts/apps.py to

class AccountsConfig(AppConfig):
    name = "capstone_project_website.apps.accounts"

and in installed apps you can see the path is:

"capstone_project_website.apps.accounts",

I have tried changing the name of... capstone_project_website/apps/contact/apps.py

class ContactConfig(AppConfig):
    name = "contact"

... to name='capstone_project_website.apps.contact' ...and my installed app name to:

INSTALLED_APPS = [
    ...
    "capstone_project_website.apps.ContactConfig", ]

Point being I am unsure what is going on, if it is a directory issue, a name issue or if there is some step I am missing before I make compose-start. If you could help me with this, and explain what I am doing wrong, I would greatly appreciate it! Thank you

like image 887
RDeaver Avatar asked Dec 31 '22 15:12

RDeaver


2 Answers

try changing this:

class ContactConfig(AppConfig): name = "contact"

to this:

class ContactConfig(AppConfig): name = "apps.contact"

like image 107
Pianoman87 Avatar answered Jan 05 '23 15:01

Pianoman87


Check your django version. If you update your django version to 3.2, try to switch with the earliest one.

django==3.1.8

like image 21
Musfiqur Rahman Avatar answered Jan 05 '23 14:01

Musfiqur Rahman