2017-05-25 20 views
0

DRFを使用してトークン認証を実装しようとすると、私の端末でこのエラーが発生します。私は他の関連のrelevant questions with solutionsを見たことがありますが、それらのどれもが私の問題を解決しませんでした。django.core.exceptions.AppRegistryNotReady:モデルはまだロードされていません.- django 1.11

以下

wsgi.py

""" 
WSGI config for myApp project. 

It exposes the WSGI callable as a module-level variable named ``application``. 

For more information on this file, see 
https://docs.djangoproject.com/en/1.11/howto/deployment/wsgi/ 
""" 

import os 

from django.core.wsgi import get_wsgi_application 

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "myApp.settings") 

application = get_wsgi_application() 

スタックトレース

Traceback (most recent call last): 
    File "manage.py", line 22, in <module> 
    execute_from_command_line(sys.argv) 
    File "/Users/emmnock/Desktop/peaceAppProject/lib/python2.7/site-packages/django/core/management/__init__.py", line 363, in execute_from_command_line 
    utility.execute() 
    File "/Users/emmnock/Desktop/peaceAppProject/lib/python2.7/site-packages/django/core/management/__init__.py", line 337, in execute 
    django.setup() 
    File "/Users/emmnock/Desktop/peaceAppProject/lib/python2.7/site-packages/django/__init__.py", line 27, in setup 
    apps.populate(settings.INSTALLED_APPS) 
    File "/Users/emmnock/Desktop/peaceAppProject/lib/python2.7/site-packages/django/apps/registry.py", line 108, in populate 
    app_config.import_models() 
    File "/Users/emmnock/Desktop/peaceAppProject/lib/python2.7/site-packages/django/apps/config.py", line 202, in import_models 
    self.models_module = import_module(models_module_name) 
    File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module 
    __import__(name) 
    File "/Users/emmnock/Desktop/peaceAppProject/peaceApp/peace/models.py", line 28, in <module> 
    Token.objects.get_or_create(user=user) 
    File "/Users/emmnock/Desktop/peaceAppProject/lib/python2.7/site-packages/django/db/models/manager.py", line 85, in manager_method 
    return getattr(self.get_queryset(), name)(*args, **kwargs) 
    File "/Users/emmnock/Desktop/peaceAppProject/lib/python2.7/site-packages/django/db/models/query.py", line 464, in get_or_create 
    return self.get(**lookup), False 
    File "/Users/emmnock/Desktop/peaceAppProject/lib/python2.7/site-packages/django/db/models/query.py", line 371, in get 
    clone = self.filter(*args, **kwargs) 
    File "/Users/emmnock/Desktop/peaceAppProject/lib/python2.7/site-packages/django/db/models/query.py", line 782, in filter 
    return self._filter_or_exclude(False, *args, **kwargs) 
    File "/Users/emmnock/Desktop/peaceAppProject/lib/python2.7/site-packages/django/db/models/query.py", line 800, in _filter_or_exclude 
    clone.query.add_q(Q(*args, **kwargs)) 
    File "/Users/emmnock/Desktop/peaceAppProject/lib/python2.7/site-packages/django/db/models/sql/query.py", line 1261, in add_q 
    clause, _ = self._add_q(q_object, self.used_aliases) 
    File "/Users/emmnock/Desktop/peaceAppProject/lib/python2.7/site-packages/django/db/models/sql/query.py", line 1287, in _add_q 
    allow_joins=allow_joins, split_subq=split_subq, 
    File "/Users/emmnock/Desktop/peaceAppProject/lib/python2.7/site-packages/django/db/models/sql/query.py", line 1165, in build_filter 
    lookups, parts, reffed_expression = self.solve_lookup_type(arg) 
    File "/Users/emmnock/Desktop/peaceAppProject/lib/python2.7/site-packages/django/db/models/sql/query.py", line 1045, in solve_lookup_type 
    _, field, _, lookup_parts = self.names_to_path(lookup_splitted, self.get_meta()) 
    File "/Users/emmnock/Desktop/peaceAppProject/lib/python2.7/site-packages/django/db/models/sql/query.py", line 1342, in names_to_path 
    if field.is_relation and not field.related_model: 
    File "/Users/emmnock/Desktop/peaceAppProject/lib/python2.7/site-packages/django/utils/functional.py", line 35, in __get__ 
    res = instance.__dict__[self.name] = self.func(instance) 
    File "/Users/emmnock/Desktop/peaceAppProject/lib/python2.7/site-packages/django/db/models/fields/related.py", line 115, in related_model 
    apps.check_models_ready() 
    File "/Users/emmnock/Desktop/peaceAppProject/lib/python2.7/site-packages/django/apps/registry.py", line 132, in check_models_ready 
    raise AppRegistryNotReady("Models aren't loaded yet.") 
django.core.exceptions.AppRegistryNotReady: Models aren't loaded yet. 
+0

、このようなあなたのwsgi.pyを編集してみている完全なスタックトレースを追加してください設定の関連セクション – e4c5

+0

@ e4c5 stacktrace updated – Switz

+0

あなたの問題は 'Token.objects.get_or_create(user = user)'と28行目の 'peaceApp/peace/models.py'にあります。あなたの質問に 'peaceApp/peace/models.py'を追加してください。 –

答えて

0

import os 

from django.core.wsgi import get_wsgi_application 

os.environ['DJANGO_SETTINGS_MODULE'] = 'myapp.settings' 
application = get_wsgi_application() 
関連する問題