无法修复错误“ django.core.exceptions.AppRegistryNotReady:应用尚未加载。”

时间:2018-10-20 04:48:48

标签: python django debugging configuration settings

嗨,我今天才开始我的Django项目,在尝试python manage.py migrate的过程中,出现以下错误:

Traceback (most recent call last):
  File "manage.py", line 15, in <module>
    execute_from_command_line(sys.argv)
  File "/home/danni/.local/lib/python3.6/site-packages/django/core/management/__init__.py", line 371, in execute_from_command_line
    utility.execute()
  File "/home/danni/.local/lib/python3.6/site-packages/django/core/management/__init__.py", line 365, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/danni/.local/lib/python3.6/site-packages/django/core/management/__init__.py", line 216, in fetch_command
    klass = load_command_class(app_name, subcommand)
  File "/home/danni/.local/lib/python3.6/site-packages/django/core/management/__init__.py", line 36, in load_command_class
    module = import_module('%s.management.commands.%s' % (app_name, name))
  File "/home/danni/anaconda3/lib/python3.6/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 "/home/danni/.local/lib/python3.6/site-packages/django/core/management/commands/migrate.py", line 12, in <module>
    from django.db.migrations.autodetector import MigrationAutodetector
  File "/home/danni/.local/lib/python3.6/site-packages/django/db/migrations/autodetector.py", line 11, in <module>
    from django.db.migrations.questioner import MigrationQuestioner
  File "/home/danni/.local/lib/python3.6/site-packages/django/db/migrations/questioner.py", line 9, in <module>
    from .loader import MigrationLoader
  File "/home/danni/.local/lib/python3.6/site-packages/django/db/migrations/loader.py", line 8, in <module>
    from django.db.migrations.recorder import MigrationRecorder
  File "/home/danni/.local/lib/python3.6/site-packages/django/db/migrations/recorder.py", line 9, in <module>
    class MigrationRecorder:
  File "/home/danni/.local/lib/python3.6/site-packages/django/db/migrations/recorder.py", line 22, in MigrationRecorder
    class Migration(models.Model):
  File "/home/danni/.local/lib/python3.6/site-packages/django/db/models/base.py", line 100, in __new__
    app_config = apps.get_containing_app_config(module)
  File "/home/danni/.local/lib/python3.6/site-packages/django/apps/registry.py", line 244, in get_containing_app_config
    self.check_apps_ready()
  File "/home/danni/.local/lib/python3.6/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.

然后我运行了python manage.py check并收到以下错误消息:

    raise ImproperlyConfigured("The SECRET_KEY setting must not be empty.")
django.core.exceptions.ImproperlyConfigured: The SECRET_KEY setting must not be empty.

到目前为止,我的项目结构是: 我在project/project/settings创建了一个设置文件夹,并拥有三个文件base.py(我将其重命名并从项目/项目/名称中移出),production.pystaging.py,{{1 }}仅包含一行test.py和一个空from base import *

对于帐户应用,它位于__init__.py下。而且我已经添加了apps/account。另外,我在urls.py的{​​{1}}下添加了“帐户”。

有人可以告诉我如何解决此问题吗?非常感谢!

1 个答案:

答案 0 :(得分:1)

settings.py文件更改为settings文件夹后,您必须更新manage.py文件以指向新的设置模块,位于manage.py

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'example.settings')
# Here update the string 'example.settings' to the new settings module
# e.g os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'project.settings.test')