我一直在遵循Python Crash Course 2e教程。我遇到了Django第18章中的makemigrations函数的问题。我使用startapp创建了第一个应用程序,然后试图调用makemigrations。它返回ModuleNotFoundError,但它给出了一个以'django'为后缀的应用程序名称。我所做的是:
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
字符串
这部分运行顺利,webserver工作,一切都很好。然后我打开另一个终端(在项目级别),并键入:
ll_env\Scripts\activate
python manage.py startapp learning_logs
<edited settings.py to include 'learning_logs'>
python manage.py makemigrations learning_logs
型
因此,makemigrations返回以下追溯:
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包含我的模块:
INSTALLED_APPS = [
'learning_logs'
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]
型
我的目录是:
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
型
我在Windows 10 x64,Pycharm社区2019.2.3,Python 3.8上运行。
我所尝试的:
1)改名
2)安装Django的旧版本(2.2.11)
3)调用“makemigrations”而不是“makemigrations learning_logs”
我将感谢任何帮助,因为我对此感到困惑。
2条答案
按热度按时间5vf7fwbs1#
这是因为django没有意识到你正在尝试制作一个可重用的应用程序,如果你不想制作一个可重用的应用程序,那么就从列表中删除你的应用程序名称,否则,我会再看一下https://docs.djangoproject.com/en/2.1/intro/reusable-apps/
另外,正如一条评论所提到的,列表中的应用程序名称后缺少
,
0tdrvxhp2#
您可以只执行以下操作:
字符串