2017-03-28 141 views
0

我有一個Django應用程序,錯誤應用程序尚未加載。我正在使用postgres數據庫。添加模型後發生問題。我嘗試將模型添加到已安裝的應用程序中,將django設置更改爲模型下方,向模型類中添加名稱,將元素添加到模型類中。我不確定使用django.db導入模型是否存在問題。Django應用程序尚未加載

以下是完整的錯誤

raise AppRegistryNotReady("Apps aren't loaded yet.") django.core.exceptions.AppRegistryNotReady: Apps arne't loaded yet. 

settings.py

import os 


SECRET_KEY = 'secret_key' 

# 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.10/howto/deployment/checklist/ 

# SECURITY WARNING: keep the secret key used in production secret! 


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

ALLOWED_HOSTS = [] 


# Application definition 

INSTALLED_APPS = [ 
    'django.contrib.admin', 
    'django.contrib.auth', 
    'django.contrib.contenttypes', 
    'django.contrib.sessions', 
    'django.contrib.messages', 
    'django.contrib.staticfiles', 
    'django.contrib.gis', 
    'django.contrib.sites', 
    'myapps.modelapp' 
] 

modelapp.py

from django.db import models 
from django.contrib.postgres.fields import ArrayField 

class AppClass(models.Model): 
    name = 'modelapp' 
    verbose_name = 'modelapp' 
    # Regular Django fields corresponding to the attributes in the 
    # world borders shapefile. 
    data_1 = models.CharField('data_1', max_length=30) 

    # Returns the string representation of the model. 
    def __str__(self):    # __unicode__ on Python 2 
     return self.parcel_own 

    class Meta: 
     managed = True 
     db_table = 'table_name' 
+1

請顯示* full * traceback。將'myapps.modelapp'添加到'INSTALLED_APPS'看起來非常錯誤。您應該將應用程序或應用程序配置添加到'INSTALLED_APPS'。什麼是'modelapp.py'應該是?如果它包含模型,那麼爲什麼不把它命名爲'models.py'? – Alasdair

回答

1

我想你應該添加的「安裝MyApps只是 '安裝MyApps' 代替。 modelapp'in INSTALLED_APPS。

相關問題