Search code examples
pythondjangodjango-modelsdjango-rest-framework

ModuleNotFoundError: No module named 'django.contrib.contenttyfrom datetime import timedelta'


I try to do a migration “python manage.py makemigrations ” but I get an error

Traceback (most recent call last):
  File "/home/anton/Documents/project2/backend/my_backend/manage.py", line 22, in <module>
    main()
  File "/home/anton/Documents/project2/backend/my_backend/manage.py", line 18, in main
    execute_from_command_line(sys.argv)
  File "/home/anton/Documents/project2/backend/pr2_venv/lib/python3.12/site-packages/django/core/management/__init__.py", line 442, in execute_from_command_line
    utility.execute()
  File "/home/anton/Documents/project2/backend/pr2_venv/lib/python3.12/site-packages/django/core/management/__init__.py", line 416, in execute
    django.setup()
  File "/home/anton/Documents/project2/backend/pr2_venv/lib/python3.12/site-packages/django/__init__.py", line 24, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/home/anton/Documents/project2/backend/pr2_venv/lib/python3.12/site-packages/django/apps/registry.py", line 91, in populate
    app_config = AppConfig.create(entry)
                 ^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/anton/Documents/project2/backend/pr2_venv/lib/python3.12/site-packages/django/apps/config.py", line 193, in create
    import_module(entry)
  File "/usr/lib/python3.12/importlib/__init__.py", line 90, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap>", line 1387, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1360, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1324, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'django.contrib.contenttyfrom datetime import timedelta'
INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttyfrom datetime import timedelta',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'rest_framework',
    'auth_app',
    'corsheaders'
]

P.S. I already noticed the error in INSTALLED APS

I can't find the file with this error, and I can't install this module either pip install timedelta i also did

in .env file only SECRET_KEY=django-insecure-3+qcjvwgd8r95x++s85nwz7xa+#^v2hiv7-pbgdz)b1s5)gx&w DEBUG=TRUE


Solution

  • The from datetime import timedelta does not make much sense in the INSTALLED_APPS. Likely you want to install django.contrib.contenttype, but probably due to some copy paste error, you included this import. You should rewrite the item to:

    INSTALLED_APPS = [
        'django.contrib.admin',
        'django.contrib.auth',
        'django.contrib.contenttype',
        'django.contrib.sessions',
        'django.contrib.messages',
        'django.contrib.staticfiles',
        'rest_framework',
        'auth_app',
        'corsheaders',
    ]