我有一个连接到Gmail API的Django项目。 当我尝试进行数据库迁移时,它会返回:
C:\Users\Peter\Desktop\FastProject>python manage.py migrate FastProject
Traceback (most recent call last):
File "manage.py", line 15, in <module>
execute_from_command_line(sys.argv)
File "C:\Users\Peter\AppData\Local\Programs\Python\Python36\lib\site-packages\django\core\management\__init__.py", l
ine 371, in execute_from_command_line
utility.execute()
File "C:\Users\Peter\AppData\Local\Programs\Python\Python36\lib\site-packages\django\core\management\__init__.py", l
ine 365, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Users\Peter\AppData\Local\Programs\Python\Python36\lib\site-packages\django\core\management\base.py", line
288, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Users\Peter\AppData\Local\Programs\Python\Python36\lib\site-packages\django\core\management\base.py", line
332, in execute
self.check()
File "C:\Users\Peter\AppData\Local\Programs\Python\Python36\lib\site-packages\django\core\management\base.py", line
364, in check
include_deployment_checks=include_deployment_checks,
File "C:\Users\Peter\AppData\Local\Programs\Python\Python36\lib\site-packages\django\core\management\commands\migrat
e.py", line 58, in _run_checks
issues.extend(super()._run_checks(**kwargs))
File "C:\Users\Peter\AppData\Local\Programs\Python\Python36\lib\site-packages\django\core\management\base.py", line
351, in _run_checks
return checks.run_checks(**kwargs)
File "C:\Users\Peter\AppData\Local\Programs\Python\Python36\lib\site-packages\django\core\checks\registry.py", line
73, in run_checks
new_errors = check(app_configs=app_configs)
File "C:\Users\Peter\AppData\Local\Programs\Python\Python36\lib\site-packages\django\core\checks\urls.py", line 13,
in check_url_config
return check_resolver(resolver)
File "C:\Users\Peter\AppData\Local\Programs\Python\Python36\lib\site-packages\django\core\checks\urls.py", line 23,
in check_resolver
return check_method()
File "C:\Users\Peter\AppData\Local\Programs\Python\Python36\lib\site-packages\django\urls\resolvers.py", line 397, i
n check
for pattern in self.url_patterns:
File "C:\Users\Peter\AppData\Local\Programs\Python\Python36\lib\site-packages\django\utils\functional.py", line 36,
in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "C:\Users\Peter\AppData\Local\Programs\Python\Python36\lib\site-packages\django\urls\resolvers.py", line 536, i
n url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "C:\Users\Peter\AppData\Local\Programs\Python\Python36\lib\site-packages\django\utils\functional.py", line 36,
in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "C:\Users\Peter\AppData\Local\Programs\Python\Python36\lib\site-packages\django\urls\resolvers.py", line 529, i
n urlconf_module
return import_module(self.urlconf_name)
File "C:\Users\Peter\AppData\Local\Programs\Python\Python36\lib\importlib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "C:\Users\Peter\Desktop\FastProject\FastProject\urls.py", line 21, in <module>
path('', include('mainApp.urls')),
File "C:\Users\Peter\AppData\Local\Programs\Python\Python36\lib\site-packages\django\urls\conf.py", line 34, in incl
ude
urlconf_module = import_module(urlconf_module)
File "C:\Users\Peter\AppData\Local\Programs\Python\Python36\lib\importlib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "C:\Users\Peter\Desktop\FastProject\mainApp\urls.py", line 3, in <module>
from . import views
File "C:\Users\Peter\Desktop\FastProject\mainApp\views.py", line 2, in <module>
from quickstart import go
ModuleNotFoundError: No module named 'quickstart'
我也尝试过makemigrations&#39;和旧的&#39; syncdb&#39;,但第一个给出相同的错误,第二个不再使用。我使用SQLite3。这是我的设置:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'results_db.sqlite3'),
}
}
&#34;快速启动&#34;是一个我调用函数的文件。我想所有的名字都是正确的,所以我不知道问题是什么。这是错误,但我后来决定考虑它。
感谢。
答案 0 :(得分:0)
它与这一行绝对相关:
File "C:\Users\Peter\Desktop\FastProject\mainApp\views.py", line 2, in <module>
from quickstart import go
ModuleNotFoundError: No module named 'quickstart'
您似乎错过了quickstart
模块。它与某些教程有关吗?也许你忘了激活你的虚拟环境了?
<强>更新强>
如果您有这样的项目结构https://ibb.co/fdvaRJ,您应该使用本地导入或提供包的完整路径:
from .quickstart import go
或
from mainApp.quickstart import go
或者您可以将quickstart.py
模块放在上一层,然后使用
from quickstart import go
就像你现在一样。
不要忘记查看有关Python包装和模块的官方指南:https://docs.python.org/3/tutorial/modules.html#packages
答案 1 :(得分:0)
我使用该快速启动文件进行了一些操作。首先我在每个文件夹' init .py'中创建,然后我在app目录中创建了一个空文件夹并拖动n
放在那里'quickstart.py'并在那里创建一个空的“init”文件也是。没有用:错误刚刚从ModuleNotFoundError更改:没有名为'quickstart'的模块到ModuleNotFoundError:没有名为'api.quickstart'的模块。
然后我删除了2分钟前创建的所有“init”文件,将“quickstart”文件放回到我的应用程序的根文件夹中,并拖放“初始化”文件。
错误变得像“从快速入门导入去 ImportError:无法导入名称'go'“。我接下来做的只是”从快速入门导入go“改为”import quickstart“然后调用go函数如”quickstart.go()“
太多的文字,所以图片以便更好地理解: