Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Django“模型尚未加载”_Python_Django - Fatal编程技术网

Python Django“模型尚未加载”

Python Django“模型尚未加载”,python,django,Python,Django,我已经有一段时间没有处理django了,我正在处理一些可能有点旧的代码,现在在django 1.7上。这是关于什么的 它不是通过runserver实现的,而是通过使用应用程序模型的命令行实用程序实现的。前面的问题已经指出升级已经完成的wsgi文件并创建已经完成的AppConfig对象,尽管可能不完全详细 Traceback (most recent call last): File "files/hashcat.py", line 34, in <module> proc

我已经有一段时间没有处理django了,我正在处理一些可能有点旧的代码,现在在django 1.7上。这是关于什么的

它不是通过runserver实现的,而是通过使用应用程序模型的命令行实用程序实现的。前面的问题已经指出升级已经完成的wsgi文件并创建已经完成的AppConfig对象,尽管可能不完全详细

Traceback (most recent call last):
  File "files/hashcat.py", line 34, in <module>
    process.processFile(line)
  File "/home/x/dataidentity/files/processing/process.py", line 81, in processFile
    af.analyze()
  File "/home/x/dataidentity/files/filetype/AnalysisFactory.py", line 40, in analyze
    self.getOrCreateFileNameModel()
  File "/home/x/dataidentity/files/filetype/AnalysisFactory.py", line 51, in getOrCreateFileNameModel
    basefile=self.fileModel)
  File "/home/x/venv/local/lib/python2.7/site-packages/django/db/models/query.py", line 679, in filter
    return self._filter_or_exclude(False, *args, **kwargs)
  File "/home/x/venv/local/lib/python2.7/site-packages/django/db/models/query.py", line 697, in _filter_or_exclude
    clone.query.add_q(Q(*args, **kwargs))
  File "/home/x/venv/local/lib/python2.7/site-packages/django/db/models/sql/query.py", line 1304, in add_q
    clause, require_inner = self._add_q(where_part, self.used_aliases)
  File "/home/x/venv/local/lib/python2.7/site-packages/django/db/models/sql/query.py", line 1332, in _add_q
    allow_joins=allow_joins, split_subq=split_subq,
  File "/home/x/venv/local/lib/python2.7/site-packages/django/db/models/sql/query.py", line 1144, in build_filter
    lookups, parts, reffed_aggregate = self.solve_lookup_type(arg)
  File "/home/x/venv/local/lib/python2.7/site-packages/django/db/models/sql/query.py", line 1030, in solve_lookup_type
    _, field, _, lookup_parts = self.names_to_path(lookup_splitted, self.get_meta())
  File "/home/x/venv/local/lib/python2.7/site-packages/django/db/models/sql/query.py", line 1367, in names_to_path
    if field.is_relation and not field.related_model:
  File "/home/x/venv/local/lib/python2.7/site-packages/django/utils/functional.py", line 60, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "/home/x/venv/local/lib/python2.7/site-packages/django/db/models/fields/related.py", line 110, in related_model
    apps.check_models_ready()
  File "/home/x/venv/local/lib/python2.7/site-packages/django/apps/registry.py", line 131, in check_models_ready
    raise AppRegistryNotReady("Models aren't loaded yet.")
django.core.exceptions.AppRegistryNotReady: Models aren't loaded yet.

在命令行中使用应用程序的模型之前-

import django
django.setup()

在命令行中使用应用程序的模型之前-

import django
django.setup()

在wsgi文件中包含以下代码并进行检查

from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

在wsgi文件中包含以下代码并进行检查

from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

如果从外部脚本使用Django,则必须在使用任何模型之前运行Django.setup。如果从外部脚本使用Django,则必须在使用任何模型之前运行Django.setup。