django-balanced - 数据库错误

时间:2013-07-29 15:12:05

标签: mysql django

我正在尝试在我的项目中安装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.
    }
}

2 个答案:

答案 0 :(得分:0)

您需要设置DJANGO_SETTINGS_MODULE:

You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings

答案 1 :(得分:0)

您还可以输入以下命令

BALANCED_API_KEY=YOUR_API_KEY python manage.py syncdb