本文介绍了Django“模型未被加载”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
自从我处理了django以来,我已经有一段时间了,我正在处理一些可能会更老的代码,现在在Django 1.7上。这个堆栈跟踪是什么?它不是通过 runserver
发生的,而是通过使用的命令行实用程序一个应用程序的模型。以前的问题已经指出了升级wsgi文件(已经完成)并创建了一个 AppConfig
对象(已完成,尽管可能不完整)
$ b
追溯(最近的最后一次呼叫):
文件files / hashcat.py,第34行,< module> ;
process.processFile(line)
文件/home/x/dataidentity/files/processing/process.py,第81行,在processFile
af.analyze()
文件/home/x/dataidentity/files/filetype/AnalysisFactory.py,第40行,分析
self.getOrCreateFileNameModel()
文件/ home / x / dataidentity / files / filetype / AnalysisFactory .py,第51行,getOrCreateFileNameModel
basefile = self.fileModel)
文件/home/x/venv/local/lib/python2.7/site-packages/django/db/models/ query.py,第679行,过滤器
return self._filter_or_exclude(False,* args,** kwargs)
文件/home/x/venv/local/lib/python2.7/site $ p $ / $ / $ / $ / $ / $ / $ / $ / $ / $ / $ / $ / $ / $ / $ /在add_q
子句中,require_inner = self._add_q(where_part,self.used_aliases),第1304行,第一行,第一行,第二行,第二行,第二行,
文件/home/x/venv/local/lib/python2.7/site-packa ges / django / db / models / sql / query.py,第1332行,_add_q
allow_joins = allow_joins,split_subq = split_subq,
文件/ home / x / venv / local / lib / python2 .7 / site-packages / django / db / models / sql / query.py,第1144行,build_filter
lookups,parts,reffed_aggregate = self.solve_lookup_type(arg)
文件/ home / x / venv / local / lib / python2.7 / site-packages / django / db / models / sql / query.py,第1030行,solve_lookup_type
_,field,_,lookup_parts = self.names_to_path lookup_splitted,self.get_meta())
文件/home/x/venv/local/lib/python2.7/site-packages/django/db/models/sql/query.py,第1367行, names_to_path
如果field.is_relation而不是field.related_model:
文件/home/x/venv/local/lib/python2.7/site-packages/django/utils/functional.py,行60,in __get__
res = instance .__ dict __ [self.name] = self.func(instance)
文件/home/x/venv/local/lib/python2.7/site-packages/ django / db / models / fields / related.py,第110行,在related_model $ b $中b apps.check_models_ready()
文件/home/x/venv/local/lib/python2.7/site-packages/django/apps/registry.py,第131行,check_models_ready
raise AppRegistryNotReady(模型尚未加载。)
django.core.exceptions.AppRegistryNotReady:模型尚未加载。
解决方案
在命令行中使用应用程序的模型之前 - p>
import django
django.setup()
It's been quite a while since I've dealt with django, I'm dealing with some code that may be a bit older, now on Django 1.7. What is this stacktrace about?
It occurs not via runserver
, but rather via a command-line utility that uses an app's models. Previous questions have pointed to upgrading the wsgi file (which has been done) and creating an AppConfig
object (which has been done, albeit it's possible not in complete detail).
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.
解决方案
Before using your app's models in Command line -
import django
django.setup()
这篇关于Django“模型未被加载”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!