0

django-balancedプロジェクトにアプリをインストールしようとしていますが、エラーが発生します。readmeファイルにあるように、次のことを行いました。

#Add to settings
import os

BALANCED = {
    'API_KEY': os.environ.get('BALANCED_API_KEY'),
}

INSTALLED_APPS = (
   ...
   'django.contrib.admin',  # if you want to use the admin interface
   'django_balanced',
   ...
)


#ran the following on my project root folder
BALANCED_API_KEY=YOUR_API_KEY django-admin.py syncdb #replacing the YOUR_API_KEY with my key

これを行うと、次のエラーが表示されます。

Traceback (most recent call last):

  File "/usr/local/bin/django-admin.py", line 5, in <module>

    management.execute_from_command_line()

  File "/Library/Python/2.7/site-packages/django/core/management/__init__.py", line 453, in execute_from_command_line

    utility.execute()

  File "/Library/Python/2.7/site-packages/django/core/management/__init__.py", line 392, in execute

    self.fetch_command(subcommand).run_from_argv(self.argv)

  File "/Library/Python/2.7/site-packages/django/core/management/__init__.py", line 272, in fetch_command

    klass = load_command_class(app_name, subcommand)

  File "/Library/Python/2.7/site-packages/django/core/management/__init__.py", line 77, in load_command_class

    module = import_module('%s.management.commands.%s' % (app_name, name))

  File "/Library/Python/2.7/site-packages/django/utils/importlib.py", line 35, in import_module

    __import__(name)

  File "/Library/Python/2.7/site-packages/django/core/management/commands/syncdb.py", line 8, in <module>

    from django.core.management.sql import custom_sql_for_model, emit_post_sync_signal

  File "/Library/Python/2.7/site-packages/django/core/management/sql.py", line 9, in <module>

    from django.db import models

  File "/Library/Python/2.7/site-packages/django/db/__init__.py", line 11, in <module>

    if settings.DATABASES and DEFAULT_DB_ALIAS not in settings.DATABASES:

  File "/Library/Python/2.7/site-packages/django/conf/__init__.py", line 53, in __getattr__

    self._setup(name)

  File "/Library/Python/2.7/site-packages/django/conf/__init__.py", line 46, in _setup

    % (desc, ENVIRONMENT_VARIABLE))

django.core.exceptions.ImproperlyConfigured: Requested setting DATABASES, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings. 

python manage.py syncdb を実行すると、データベースでエラーが発生しません。readme ファイルに記載されていないデータベース設定の何かが欠けている可能性があります。前もって感謝します

ここに私のデータベース設定があります:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
        'NAME': 'payload',                      # Or path to database file if using sqlite3.
        'USER': 'root',                      # Not used with sqlite3.
        'PASSWORD': 'pass123',                  # Not used with sqlite3.
        'HOST': '',                      # Set to empty string for localhost. Not used with sqlite3.
        'PORT': '',                      # Set to empty string for default. Not used with sqlite3.
    }
}
4

2 に答える 2

0

DJANGO_SETTINGS_MODULE を設定する必要があります。

You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings
于 2013-07-29T15:22:01.257 に答える
0

次のコマンドを入力することもできます

BALANCED_API_KEY=YOUR_API_KEY python manage.py syncdb
于 2013-07-29T16:41:18.130 に答える