Programing

Django를 1.9 오류로 업그레이드하는 중 "AppRegistryNotReady : 앱이 아직로드되지 않았습니다."

lottogame 2020. 11. 1. 17:14
반응형

Django를 1.9 오류로 업그레이드하는 중 "AppRegistryNotReady : 앱이 아직로드되지 않았습니다."


1.8에서 django 1.9로 업그레이드 할 때이 오류가 발생했습니다. 비슷한 질문에 대한 답변을 확인했지만 타사 패키지 또는 앱의 문제라고 생각하지 않았습니다.

Traceback (most recent call last):
File "manage.py", line 10, in <module> execute_from_command_line(sys.argv)
File "/home/kishore/.virtualenvs/andone/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 350, in execute_from_command_line
utility.execute()
File "/home/kishore/.virtualenvs/andone/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 342, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/kishore/.virtualenvs/andone/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 176, in fetch_command
commands = get_commands()
File "/home/kishore/.virtualenvs/andone/local/lib/python2.7/site-packages/django/utils/lru_cache.py", line 100, in wrapper
result = user_function(*args, **kwds)
File "/home/kishore/.virtualenvs/andone/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 71, in get_commands
for app_config in reversed(list(apps.get_app_configs())):
File "/home/kishore/.virtualenvs/andone/local/lib/python2.7/site-packages/django/apps/registry.py", line 137, in get_app_configs
self.check_apps_ready()
File "/home/kishore/.virtualenvs/andone/local/lib/python2.7/site-packages/django/apps/registry.py", line 124, in check_apps_ready
raise AppRegistryNotReady("Apps aren't loaded yet.")
django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.

'django.contrib.auth'에 대해 설치된 앱을 수정했습니다.


설정 파일의 맨 위에 다음 행을 추가하십시오.

import django
django.setup()

그리고 이것이 도움이되지 않는다면 설치된 앱 목록에서 타사 애플리케이션을 하나씩 제거해보십시오.


내 모델 __init__.py파일 중 하나에 작성된 사용자 지정 함수였습니다 . 오류가 발생했습니다. 이 기능을 옮겼을 때 __init__.py작동했습니다.


내가 만든 때 내 경우, 오류가 발생했습니다 python manage.py makemigrationsDjango 2.0.6.

해결책은 실행 python manage.py runserver하고 실제 오류 (단지 누락 된 환경 변수)를 확인하는 것이 었습니다.


내 문제는 호출하기 전에 Django 모델을 가져 오려고했다는 것입니다. django.setup()

이것은 나를 위해 일했습니다.

import django
django.setup()

from myapp.models import MyModel

위의 스크립트는 프로젝트 루트 폴더에 있습니다.


당신이 응용 프로그램을 추가 할 때이 오류가 발생할 수 있습니다 INSTALLED_APPS에서 settings.py파일하지만 당신은 응용 프로그램이 컴퓨터에 설치되어 있지 않습니다. 두 가지 해결책이 있습니다.

  1. Installpip우분투 와 같은 패키지 관리자를 사용하는 앱
  2. 또는 설치된 앱을 settings.py파일 에 주석 처리

이 오류는 virtual environment프로젝트에 대해 생성 한 사용자 가 아닌 경우에도 발생할 수 있습니다.


전체 settings.LOGGINGdictConfig를 제거하고 서버를 다시 시작하십시오. 작동하면 v1.9 문서에 따라 설정을 다시 작성하십시오.

https://docs.djangoproject.com/en/1.9/topics/logging/#examples


저에게 문제는 파일 INSTALLED_APPS에서 모델을 가져 오는 앱을 가져오고 있다는 사실 에서 발생했습니다.__init__.py

나는 가지고 있었다 :

settings.py

INSTALLED_APPS = [
    ...
    'myapp',
    ...
]

myapp.__init__.py

from django.contrib.sites.models import Site

주석 import models에서 myapp.__init__.py작동했다 :

# from django.contrib.sites.models import Site

나를 위해 주석 처리

'grappelli.dashboard',
'grappelli',

INSTALLED_APPS에서 작동 함


스크립트를 명시 적으로 실행하는 동안 상단의 django.setup ()은 작동하지 않습니다. 설정 파일 하단에 이것을 추가했을 때 내 문제가 해결되었습니다.

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
import sys
if BASE_DIR not in sys.path:
    sys.path.append(BASE_DIR)
os.environ['DJANGO_SETTINGS_MODULE'] =  "igp_lrpe.settings"
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "igp_lrpe.settings")
import django
django.setup()

내 문제는 : django-reversion> = 1.8.7, <1.9

django 1.9.7의 경우 다음을 사용해야합니다. django-reversion == 1.10.0

django-cms 3.2를 3.3으로 업그레이드했고 앱에 주석을 달고 다시 주석 처리를 해제하여 찾았습니다.

여기에서 정답 : https://stackoverflow.com/a/34040556/2837890


This issue is also observed for inconsistent settings.py for incorrectly writing INSTALLED_APPS, verify if you correctly included apps and separated with "," .


When I change my django version to 1.9, it don't arise the error. pip uninstall django pip install django==1.9


I put the User import into the settings file for managing the rest call token like this

# settings.py
from django.contrib.auth.models import User
def jwt_get_username_from_payload_handler(payload):
   ....

JWT_AUTH = {
    'JWT_PAYLOAD_GET_USERNAME_HANDLER': jwt_get_username_from_payload_handler,
    'JWT_PUBLIC_KEY': PUBLIC_KEY,
    'JWT_ALGORITHM': 'RS256',
    'JWT_AUDIENCE': API_IDENTIFIER,
    'JWT_ISSUER': JWT_ISSUER,
    'JWT_AUTH_HEADER_PREFIX': 'Bearer',
}
REST_FRAMEWORK = {
    'DEFAULT_PERMISSION_CLASSES': (
        'rest_framework.permissions.IsAuthenticated',
    ),
    'DEFAULT_AUTHENTICATION_CLASSES': (
       'rest_framework_jwt.authentication.JSONWebTokenAuthentication',
    ),
}

Because at that moment, Django libs are not ready yet. Therefore, I put the import inside the function and it started to work. The function needs to be called after the server is started


In my case one of my settings, 'CORS_ORIGIN_WHITELIST' was set in the settings.py file but was not available in my .env file. So I'll suggest that you check your settings, especially those linked to .env


As others have said this can be caused when you've not installed an app that is listed in INSTALLED_APPS.

In my case, manage.py was attempting to log the exception, which led to an attempt to render it which failed due to the app not being initialized yet. By commenting out the except clause in manage.py the exception was displayed without special rendering, avoiding the confusing error.

# Temporarily commenting out the log statement.
#try:
    execute_from_command_line(sys.argv)
#except Exception as e:
#    log.error('Admin Command Error: %s', ' '.join(sys.argv), exc_info=sys.exc_info())
#    raise e

I tried tons of things, but only downgrading Django to 1.8.18 fixed this issue for me:

pip install django==1.8.18

It is one of the installed apps that is failing, but I could not find which one.


Got this error while trying to access model objects in apps.py:

class QuizConfig(AppConfig):
name = 'quiz'

def ready(self):
    print('===============> Django just started....')
    questions_by_category = Question.objects.filter(category=2) # <=== Guilty line of code.

Trying to access Question before the app has loaded the model class caused the error for me.


Late to the party, but grappelli was the reason for my error as well. I looked up the compatible version on pypi and that fixed it for me.


Try activating the virtual env. In my case, using the git command line tool:

source scripts/activate

Solves my problem.


If your setting.py files fill are correct,you can try to arrive manage.py files proceed call danjgo.setup() in main method . Then run manage.py ,finally again run project ,the issue could disappear.


In the "admin" module of your app package, do register all the databases created in "models" module of the package.

Suppose you have a database class defined in "models" module as:

class myDb1(models.Model):
    someField= models.Charfiled(max_length=100)

so you must register this in the admin module as:

from .models import myDb1
admin.site.register(myDb1)

I hope this resolve the error.

참고URL : https://stackoverflow.com/questions/34114427/django-upgrading-to-1-9-error-appregistrynotready-apps-arent-loaded-yet

반응형