In python Django, I want to query a foreignKey coloumn of a table, it raise django.core.exceptions.AppRegistryNotReady: Models aren't loaded yet -
i have app name publisher. run code in publisher/views.py. runs ok inserting entries , newspapers = newspaper.objects.values('newspaper_link')
tables ok when view in sqlite db browser. when run
newspapers = newspaper.objects.values('country_id')
or
newspapers = newspaper.objects.values()
it raise
django.core.exceptions.appregistrynotready: models aren't loaded yet.
here publisher/models.py:
from django.db import models class country(models.model): country_link = models.urlfield() country_name = models.textfield(primary_key=true) class newspaper(models.model): newspaper_link = models.urlfield(primary_key=true) newspaper_name = models.textfield() country = models.foreignkey(country)
here traceback information:
traceback (most recent call last): file "d:/teamproject/djangoprojectone/djangoprojectone/mysite/publisher/views.py", line 99, in <module> preorder('a') file "d:/teamproject/djangoprojectone/djangoprojectone/mysite/publisher/views.py", line 78, in preorder newspapers = newspaper.objects.values() file "c:\users\joy zhang\anaconda3\lib\site-packages\django\db\models\manager.py", line 127, in manager_method return getattr(self.get_queryset(), name)(*args, **kwargs) file "c:\users\joy zhang\anaconda3\lib\site-packages\django\db\models\query.py", line 606, in values return self._clone(klass=valuesqueryset, setup=true, _fields=fields) file "c:\users\joy zhang\anaconda3\lib\site-packages\django\db\models\query.py", line 960, in _clone c._setup_query() file "c:\users\joy zhang\anaconda3\lib\site-packages\django\db\models\query.py", line 1136, in _setup_query self.query.add_fields(self.field_names, true) file "c:\users\joy zhang\anaconda3\lib\site-packages\django\db\models\sql\query.py", line 1692, in add_fields name.split(lookup_sep), opts, alias, allow_many=allow_m2m) file "c:\users\joy zhang\anaconda3\lib\site-packages\django\db\models\sql\query.py", line 1466, in setup_joins names, opts, allow_many, fail_on_missing=true) file "c:\users\joy zhang\anaconda3\lib\site-packages\django\db\models\sql\query.py", line 1367, in names_to_path if field.is_relation , not field.related_model: file "c:\users\joy zhang\anaconda3\lib\site-packages\django\utils\functional.py", line 60, in __get__ res = instance.__dict__[self.name] = self.func(instance) file "c:\users\joy zhang\anaconda3\lib\site-packages\django\db\models\fields\related.py", line 110, in related_model apps.check_models_ready() file "c:\users\joy zhang\anaconda3\lib\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.
here installed_apps in settings:
installed_apps = ( 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'rss', 'tweet', 'publisher' )
from traceback, appear calling preorder
function @ module level. don't function doing, cause of error. should call model methods within views, or functions called view.
Comments
Post a Comment