Django 2.0迁移错误:“ django.core.exceptions.AppRegistryNotReady:应用尚未加载。”

时间:2018-06-24 17:44:53

标签: python django migration models django-2.0

我在使用django时遇到了麻烦。我正在使用一个应用程序启动一个新项目,并且当我添加一个模型时,无法迁移它。

迁移(或进行迁移)时出现错误消息:

    (MapEnv) C:\Users\rossi\Desktop\Imp!act\MapEnv\ActorMap>django-admin migrate
Traceback (most recent call last):
  File "c:\users\rossi\appdata\local\programs\python\python36-32\Lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "c:\users\rossi\appdata\local\programs\python\python36-32\Lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\Users\rossi\Desktop\Imp!act\MapEnv\Scripts\django-admin.exe\__main__.py", line 9, in <module>
  File "c:\users\rossi\desktop\imp!act\mapenv\lib\site-packages\django\core\management\__init__.py", line 371, in execute_from_command_line
    utility.execute()
  File "c:\users\rossi\desktop\imp!act\mapenv\lib\site-packages\django\core\management\__init__.py", line 365, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "c:\users\rossi\desktop\imp!act\mapenv\lib\site-packages\django\core\management\__init__.py", line 216, in fetch_command
    klass = load_command_class(app_name, subcommand)
  File "c:\users\rossi\desktop\imp!act\mapenv\lib\site-packages\django\core\management\__init__.py", line 36, in load_command_class
    module = import_module('%s.management.commands.%s' % (app_name, name))
  File "c:\users\rossi\desktop\imp!act\mapenv\lib\importlib\__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 994, in _gcd_import
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 678, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "c:\users\rossi\desktop\imp!act\mapenv\lib\site-packages\django\core\management\commands\migrate.py", line 12, in <module>
    from django.db.migrations.autodetector import MigrationAutodetector
  File "c:\users\rossi\desktop\imp!act\mapenv\lib\site-packages\django\db\migrations\autodetector.py", line 11, in <module>
    from django.db.migrations.questioner import MigrationQuestioner
  File "c:\users\rossi\desktop\imp!act\mapenv\lib\site-packages\django\db\migrations\questioner.py", line 9, in <module>
    from .loader import MigrationLoader
  File "c:\users\rossi\desktop\imp!act\mapenv\lib\site-packages\django\db\migrations\loader.py", line 8, in <module>
    from django.db.migrations.recorder import MigrationRecorder
  File "c:\users\rossi\desktop\imp!act\mapenv\lib\site-packages\django\db\migrations\recorder.py", line 9, in <module>
    class MigrationRecorder:
  File "c:\users\rossi\desktop\imp!act\mapenv\lib\site-packages\django\db\migrations\recorder.py", line 22, in MigrationRecorder
    class Migration(models.Model):
  File "c:\users\rossi\desktop\imp!act\mapenv\lib\site-packages\django\db\models\base.py", line 100, in __new__
    app_config = apps.get_containing_app_config(module)
  File "c:\users\rossi\desktop\imp!act\mapenv\lib\site-packages\django\apps\registry.py", line 244, in get_containing_app_config
    self.check_apps_ready()
  File "c:\users\rossi\desktop\imp!act\mapenv\lib\site-packages\django\apps\registry.py", line 127, in check_apps_ready
    raise AppRegistryNotReady("Apps aren't loaded yet.")
django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.

settings.py:

    """
Django settings for ActorMap project.

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

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

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

import os
import django
# 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/2.0/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '&--)s9lt4ka#yc*0**b-y&sdhwb_057qwt)%futo2(-7j88bi5'

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

ALLOWED_HOSTS = ['192.168.1.13']


# Application definition

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',

]

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

ROOT_URLCONF = 'ActorMap.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 = 'ActorMap.wsgi.application'


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

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': '*****',
        'USER': '*****',
        'HOST': '127.0.0.1',
        'PASSWORD': '****'
    }
}


# Password validation
# https://docs.djangoproject.com/en/2.0/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/2.0/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/2.0/howto/static-files/

STATIC_URL = '/static/'

我在单个应用中的单个模型:

from django.db import models

# Create your models here.

class Actor(models.Model):
    compagny = models.CharField(max_length=255, null=True)
    full_name = models.CharField(max_length=255, null=True)
    mail = models.EmailField(null=True)
    tel = models.CharField(max_length=15, null=True)
    address = models.TextField(null=True)
    latitude = models.FloatField(null=True)
    longitude = models.FloatField(null=True)
    description = models.TextField(null=True)
    domain = models.CharField(max_length=255, null=True)
    website = models.URLField(null=True)

我在django.setup()上看到了一些东西,但是我不确定它是否是我所需要的,有些版本有所不同。我正在使用安装在virtualenv上的django 2.0.6和python 3.6。

我该怎么办?感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

(MapEnv) C:\Users\rossi\Desktop\Imp!act\MapEnv\ActorMap>django-admin migrate

必须为manage.py migrate ...