Hi. I have just started building my first django app and am currently stuck at the part where I’m supposed to be executing a makemigrations command to create a new model called ‘userprofile’ right after I have added a reference to the configuration class in the INSTALLED_APPS setting.
Upon executing the ‘python manage.py makemigrations’ command in the terminal, I received this error:
Traceback (most recent call last):
File "C:\Users\Hillis\Documents\Olasac\olasac_3_10_5\lib\site-packages\django\apps\config.py", line 244, in create
app_module = import_module(app_name)
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 965, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'core'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "manage.py", line 22, in <module>
main()
File "manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "C:\Users\Hillis\Documents\Olasac\olasac_3_10_5\lib\site-packages\django\core\management\__init__.py", line 419, in execute_from_command_line
utility.execute()
File "C:\Users\Hillis\Documents\Olasac\olasac_3_10_5\lib\site-packages\django\core\management\__init__.py", line 395, in execute
django.setup()
File "C:\Users\Hillis\Documents\Olasac\olasac_3_10_5\lib\site-packages\django\__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "C:\Users\Hillis\Documents\Olasac\olasac_3_10_5\lib\site-packages\django\apps\registry.py", line 91, in populate
app_config = AppConfig.create(entry)
File "C:\Users\Hillis\Documents\Olasac\olasac_3_10_5\lib\site-packages\django\apps\config.py", line 250, in create
app_config_class.__qualname__,
django.core.exceptions.ImproperlyConfigured: Cannot import 'core'. Check that 'apps.core.apps.CoreConfig.name' is correct.
This is my settings.py file. I have added the references “apps.core” and “apps.userprofile”:
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'apps.core',
'apps.userprofile',
]
When I removed ‘apps.core’, from INSTALLED_APPS and executed the ‘python manage.py makemigrations’ command in the terminal, I received this error:
Traceback (most recent call last):
File "C:\Users\Hillis\Documents\Olasac\olasac_3_10_5\lib\site-packages\django\apps\config.py", line 244, in create
app_module = import_module(app_name)
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 965, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'userprofile'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "manage.py", line 22, in <module>
main()
File "manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "C:\Users\Hillis\Documents\Olasac\olasac_3_10_5\lib\site-packages\django\core\management\__init__.py", line 419, in execute_from_command_line
utility.execute()
File "C:\Users\Hillis\Documents\Olasac\olasac_3_10_5\lib\site-packages\django\core\management\__init__.py", line 395, in execute
django.setup()
File "C:\Users\Hillis\Documents\Olasac\olasac_3_10_5\lib\site-packages\django\__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "C:\Users\Hillis\Documents\Olasac\olasac_3_10_5\lib\site-packages\django\apps\registry.py", line 91, in populate
app_config = AppConfig.create(entry)
File "C:\Users\Hillis\Documents\Olasac\olasac_3_10_5\lib\site-packages\django\apps\config.py", line 250, in create
app_config_class.__qualname__,
django.core.exceptions.ImproperlyConfigured: Cannot import 'userprofile'. Check that 'apps.userprofile.apps.UserprofileConfig.name' is correct.
When I execute the command ‘python manage.py makemigrations userprofile’ in the terminal, I receive the same error displayed above.
My ‘userprofile’ directory listings are as follows:
userprofile
userprofile_pycache_
userprofile\migrations
userprofile\migrations_init_.py
userprofile_init_.py
userprofile\admin.py
userprofile\apps.py
userprofile\models.py
userprofile\tests.py
userprofile\views.py
(The userprofile folder [and another folder called core] is in a folder called apps; which is in a folder called olasac).
This is my apps.py file:
from django.apps import AppConfig
class UserprofileConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'userprofile'
This is my models.py file:
#
#
from django.contrib.auth.models import User
from django.db import models
#
# Models
class Userprofile(models.Model):
user = models.ForeignKey(User, related_name='userprofile', on_delete=models.CASCADE)
active_team_id = models.IntegerField(default=0)
Django version-3.2.14
Python version-3.10.5
Pip version-20.1.1
I have also included a screenshot of my settings.py file in case there is some info I forgot to mention. The entire directory is visible in the image. Would have liked to add more but new users can only add one item of embedded media.
I suspect the problem may be due to the placement of my file directories but at this point, I’ve hit a brick wall and am not able to proceed with the project. Any advice?
Thanks in advance!