Issue
I've been following the Python Crash Course 2e tutorial. I encountered a problem with makemigrations function from Django chapter(18). I created first app using startapp, and then tried to call makemigrations. It returns ModuleNotFoundError but it gives an app name suffixed by 'django'. What I did was:
python -m venv ll_env
ll_env\Scripts\activate
pip install django (installed asgiref-3.2.3 django-3.0.3 pytz-2019.3 sqlparse-0.3.1)
django-admin startproject learning_log .
python manage.py migrate
python manage.py runserver
This part runs smoothly, webserver works, everything is great. Then I opened another terminal(on project level), and typed:
ll_env\Scripts\activate
python manage.py startapp learning_logs
<edited settings.py to include 'learning_logs'>
python manage.py makemigrations learning_logs
As a result makemigrations returns this traceback:
Traceback (most recent call last):
File "manage.py", line 21, in <module>
main()
File "manage.py", line 17, in main
execute_from_command_line(sys.argv)
File "C:\Users\Admin\PycharmProjects\djangoproj\ll_env\lib\site-packages\django\core\management\__init__.py", line 401, in execute_from_command_line
utility.execute()
File "C:\Users\Admin\PycharmProjects\djangoproj\ll_env\lib\site-packages\django\core\management\__init__.py", line 377, in execute
django.setup()
File "C:\Users\Admin\PycharmProjects\djangoproj\ll_env\lib\site-packages\django\__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "C:\Users\Admin\PycharmProjects\djangoproj\ll_env\lib\site-packages\django\apps\registry.py", line 91, in populate
app_config = AppConfig.create(entry)
File "C:\Users\Admin\PycharmProjects\djangoproj\ll_env\lib\site-packages\django\apps\config.py", line 116, in create
mod = import_module(mod_path)
File "C:\Users\Admin\AppData\Local\Programs\Python\Python38-32\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 961, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 973, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'learning_logsdjango'
settings.py include my module:
INSTALLED_APPS = [
'learning_logs'
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]
My directory is:
projectFolder/
learning_log/
__init__.py
settings.py
urls.py
wsgi.py
learning_logs/
migrations/
__init__.py
__init__.py
admin.py
apps.py
models.py
tests.py
views.py
ll_env/
include/
Lib/
Scripts/
venv/
db.sqlite3
manage.py
I am running on Windows 10 x64, Pycharm Community 2019.2.3, Python 3.8.
What I tried:
1) changing the name
2) installing a previous version of django (2.2.11)
3) calling 'makemigrations' instead of 'makemigrations learning_logs'
I will appreciate any help, as I am quite confused with this.
Solution
This is because django doesn't recognize that you are trying to make a reusable app, if you aren't trying to make a reusable app, then just remove your app name from the list, otherwise, I'd take another look at https://docs.djangoproject.com/en/2.1/intro/reusable-apps/
also, as a comment mentions, you are missing a ,
after your app name in the list
Answered By - iggy12345
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.