我在Django RESTful Framework上创建了一个宁静的API,当我运行命令时所有突然的API应用程序都无法启动
python manage.py runserver
这是完整的异常日志:
Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x7f778bc98f28>
Traceback (most recent call last):
File "/home/developer/venv/lib/python3.6/site-packages/django/utils/autoreload.py", line 225, in wrapper
fn(*args, **kwargs)
File "/home/developer/venv/lib/python3.6/site-packages/django/core/management/commands/runserver.py", line 109, in inner_run
autoreload.raise_last_exception()
File "/home/developer/venv/lib/python3.6/site-packages/django/utils/autoreload.py", line 248, in raise_last_exception
raise _exception[1]
File "/home/developer/venv/lib/python3.6/site-packages/django/core/management/__init__.py", line 337, in execute
autoreload.check_errors(django.setup)()
File "/home/developer/venv/lib/python3.6/site-packages/django/utils/autoreload.py", line 225, in wrapper
fn(*args, **kwargs)
File "/home/developer/venv/lib/python3.6/site-packages/django/__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "/home/developer/venv/lib/python3.6/site-packages/django/apps/registry.py", line 112, in populate
app_config.import_models()
File "/home/developer/venv/lib/python3.6/site-packages/django/apps/config.py", line 198, in import_models
self.models_module = import_module(models_module_name)
File "/home/developer/venv/lib/python3.6/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 "/home/developer/note_api/main/models.py", line 21, in <module>
Token.objects.get_or_create(user=user)
File "/home/developer/venv/lib/python3.6/site-packages/django/db/models/manager.py", line 82, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/home/developer/venv/lib/python3.6/site-packages/django/db/models/query.py", line 486, in get_or_create
return self.get(**lookup), False
File "/home/developer/venv/lib/python3.6/site-packages/django/db/models/query.py", line 390, in get
clone = self.filter(*args, **kwargs)
File "/home/developer/venv/lib/python3.6/site-packages/django/db/models/query.py", line 844, in filter
return self._filter_or_exclude(False, *args, **kwargs)
File "/home/developer/venv/lib/python3.6/site-packages/django/db/models/query.py", line 862, in _filter_or_exclude
clone.query.add_q(Q(*args, **kwargs))
File "/home/developer/venv/lib/python3.6/site-packages/django/db/models/sql/query.py", line 1263, in add_q
clause, _ = self._add_q(q_object, self.used_aliases)
File "/home/developer/venv/lib/python3.6/site-packages/django/db/models/sql/query.py", line 1287, in _add_q
split_subq=split_subq,
File "/home/developer/venv/lib/python3.6/site-packages/django/db/models/sql/query.py", line 1164, in build_filter
lookups, parts, reffed_expression = self.solve_lookup_type(arg)
File "/home/developer/venv/lib/python3.6/site-packages/django/db/models/sql/query.py", line 1028, in solve_lookup_type
_, field, _, lookup_parts = self.names_to_path(lookup_splitted, self.get_meta())
File "/home/developer/venv/lib/python3.6/site-packages/django/db/models/sql/query.py", line 1365, in names_to_path
if field.is_relation and not field.related_model:
File "/home/developer/venv/lib/python3.6/site-packages/django/utils/functional.py", line 37, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/home/developer/venv/lib/python3.6/site-packages/django/db/models/fields/related.py", line 94, in related_model
apps.check_models_ready()
File "/home/developer/venv/lib/python3.6/site-packages/django/apps/registry.py", line 137, in check_models_ready
raise AppRegistryNotReady("Models aren't loaded yet.")
我尝试过多次重新引导服务器,然后更改了manage.py脚本,但无济于事。
任何帮助将不胜感激。
答案 0 :(得分:0)
删除虚拟环境并制作一个新的虚拟环境,安装软件包,然后除去除 init 之外的所有迁移,删除数据库表(如果没有重要数据,则不创建新数据库;使用它)并运行:
{{1}}
然后尝试再次进行迁移,然后迁移并运行服务器,请让我知道问题是否解决