2017-09-04 13 views
0

私はdjangoフレームワークでWebプログラミングを行う方法を学習しています。Artistのインスタンスを作成しようとするとこのエラーメッセージが表示されます。私のapp modelsから。私はPython 3.6バージョンとdjango 1.11.4バージョンを使用します。 ありがとうございました ありがとうございました。Django 1.11.4:django.core.exceptions.AppRegistryNotReady:アプリケーションがまだロードされていません

File "<stdin>", line 1, in <module> 
     File ".\app\models.py", line 9, in <module> 
     class Artist(models.Model): 
     File "C:\Users\kadjo\documents\visual studio 2015\Projects\DatabaseFun\DatabaseFun\env\lib\site-packages\django\db\models\base.py", line 110, in __new__ 
     app_config = apps.get_containing_app_config(module) 
     File "C:\Users\kadjo\documents\visual studio 2015\Projects\DatabaseFun\DatabaseFun\env\lib\site-packages\django\apps\registry.py", line 247, in get_containing_app_config 
     self.check_apps_ready() 
     File "C:\Users\kadjo\documents\visual studio 2015\Projects\DatabaseFun\DatabaseFun\env\lib\site-packages\django\apps\registry.py", line 125, in check_apps_ready 
     raise AppRegistryNotReady("Apps aren't loaded yet.") 
    django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet. 

答えて

0

これは私のモデルのパッケージコードです

from django.db import models 

# Create your models here. 

class Artist(models.Model): 
    name = models.CharField("artist", max_length=50) 
    year_formed = models.PositiveIntegerField() 

class Album(models.Model): 
    name = models.CharField("album", max_length=50) 
    artist = models.ForeignKey(Artist) 

これは

""" 
Django settings for DatabaseFun project. 

Generated by 'django-admin startproject' using Django 1.9.1. 

For more information on this file, see 
https://docs.djangoproject.com/en/1.9/topics/settings/ 

For the full list of settings and their values, see 
https://docs.djangoproject.com/en/1.9/ref/settings/ 
""" 

import os 
import posixpath 

# Build paths inside the project like this: os.path.join(BASE_DIR, ...) 
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) 


# Quick-start development settings - unsuitable for production 
# See https://docs.djangoproject.com/en/1.9/howto/deployment/checklist/ 

# SECURITY WARNING: keep the secret key used in production secret! 
SECRET_KEY = 'ec5ea5b6-ee2d-43db-8bb8-4562d88788ea' 

# SECURITY WARNING: don't run with debug turned on in production! 
DEBUG = True 

ALLOWED_HOSTS = [] 


# Application definition 

INSTALLED_APPS = [ 
    'app', 
    # Add your apps here to enable them 
    'django.contrib.admin', 
    'django.contrib.auth', 
    'django.contrib.contenttypes', 
    'django.contrib.sessions', 
    'django.contrib.messages', 
    'django.contrib.staticfiles', 
    'DatabaseFun', 
] 

MIDDLEWARE_CLASSES = [ 
    'django.middleware.security.SecurityMiddleware', 
    'django.contrib.sessions.middleware.SessionMiddleware', 
    'django.middleware.common.CommonMiddleware', 
    'django.middleware.csrf.CsrfViewMiddleware', 
    'django.contrib.auth.middleware.AuthenticationMiddleware', 
    'django.contrib.auth.middleware.SessionAuthenticationMiddleware', 
    'django.contrib.messages.middleware.MessageMiddleware', 
    'django.middleware.clickjacking.XFrameOptionsMiddleware', 
] 

ROOT_URLCONF = 'DatabaseFun.urls' 

TEMPLATES = [ 
    { 
     'BACKEND': 'django.template.backends.django.DjangoTemplates', 
     'DIRS': [], 
     'APP_DIRS': True, 
     'OPTIONS': { 
      'context_processors': [ 
       'django.template.context_processors.debug', 
       'django.template.context_processors.request', 
       'django.contrib.auth.context_processors.auth', 
       'django.contrib.messages.context_processors.messages', 
      ], 
     }, 
    }, 
] 

WSGI_APPLICATION = 'DatabaseFun.wsgi.application' 


# Database 
# https://docs.djangoproject.com/en/1.9/ref/settings/#databases 

DATABASES = { 
    'default': { 
     'ENGINE': 'django.db.backends.sqlite3', 
     'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), 
    } 
} 


# Password validation 
# https://docs.djangoproject.com/en/1.9/ref/settings/#auth-password-validators 

AUTH_PASSWORD_VALIDATORS = [ 
    { 
     'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', 
    }, 
    { 
     'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', 
    }, 
    { 
     'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', 
    }, 
    { 
     'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', 
    }, 
] 


# Internationalization 
# https://docs.djangoproject.com/en/1.9/topics/i18n/ 

LANGUAGE_CODE = 'en-us' 

TIME_ZONE = 'UTC' 

USE_I18N = True 

USE_L10N = True 

USE_TZ = True 


# Static files (CSS, JavaScript, Images) 
# https://docs.djangoproject.com/en/1.9/howto/static-files/ 

STATIC_URL = '/static/' 

STATIC_ROOT = posixpath.join(*(BASE_DIR.split(os.path.sep) + ['static'])) 
0

まずパッケージコードを設定する私のアプリは、あなたのsetings.pyファイルの先頭にこれらの行を追加します。

import django 
django.setup() 

そしてこれはあなたのインストールアプリのリスト一つ一つから、サードパーティ製アプリケーションを削除しようと動作しない場合。後で再度読み込むことができます。特定のサードパーティのアプリケーションに依存している可能性があります。

希望すると助かります!

関連する問題