Django 1.11.4:Django.core.exceptions.AppRegistryNotReady:应用程序不是';还没装呢
我正在学习如何使用Django framework进行web编程,当我试图从我的Django 1.11.4:Django.core.exceptions.AppRegistryNotReady:应用程序不是';还没装呢,django,python-3.x,Django,Python 3.x,我正在学习如何使用Django framework进行web编程,当我试图从我的应用程序模型中创建我的艺术家的实例时,收到了此错误消息。我使用Python 3.6版本和Django 1.11.4版本 File "<stdin>", line 1, in <module> File ".\app\models.py", line 9, in <module> class Artist(models.Model): Fil
应用程序模型中创建我的艺术家的实例时,收到了此错误消息。我使用Python 3.6版本和Django 1.11.4版本
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.
文件“”,第1行,在
文件“.\app\models.py”,第9行,在
班级艺术家(模特、模特):
文件“C:\Users\kadjo\documents\visual studio 2015\Projects\DatabaseFun\DatabaseFun\env\lib\site packages\django\db\models\base.py”,第110行,新__
app\u config=apps.get\u包含app\u config(模块)
文件“C:\Users\kadjo\documents\visual studio 2015\Projects\DatabaseFun\DatabaseFun\env\lib\site packages\django\apps\registry.py”,第247行,包含应用程序配置的get_
self.check_apps_ready()
文件“C:\Users\kadjo\documents\visual studio 2015\Projects\DatabaseFun\DatabaseFun\env\lib\site packages\django\apps\registry.py”,第125行,在check\u apps\u ready中
raise AppRegistryNotReady(“应用程序尚未加载。”)
django.core.exceptions.AppRegistryNotReady:尚未加载应用程序。
这是我的型号包装代码
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']))
这是我的应用程序设置包代码
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']))
首先将这些行添加到settings.py文件的顶部
import django
django.setup()
然后如果这不起作用,请尝试从已安装的应用程序列表中逐个删除第三方应用程序。您可以稍后再次加载它们,这可能是因为依赖于某些第三方应用程序。您是如何运行此代码的?如果独立运行,则必须使用django.setup()
见: