0

我正在尝试django-balanced在我的项目中安装该应用程序,但出现错误。如自述文件所述,我执行了以下操作:

#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 时,数据库没有错误。我可能在数据库设置中遗漏了自述文件未提及的某些内容。提前致谢

这是我的数据库设置:

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 回答