1
$ ./manage.py sql addressbook                                                                                             
Unknown command: 'sql'

この奇妙なエラーが発生したときに、アプリのモデルによって生成された SQL を見ようとしています。

私の設定.py

import os
# Django settings for DoneBox project.

DEBUG = True
TEMPLATE_DEBUG = DEBUG

ADMINS = (
    ('Levi Campbell', 'levicc00123@gmail.com'),
)

MANAGERS = ADMINS

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'levicc00123_cc51',
        'USER': 'levicc00123_cc51',
        'PASSWORD': 'n440844291',
        'HOST': 'mysql0.db.koding.com',
        'PORT': 3306,
        }
    }
# Local time zone for this installation. Choices can be found here:
# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
# although not all choices may be available on all operating systems.
# In a Windows environment this must be set to your system time zone.
TIME_ZONE = 'America/Denver'

# Language code for this installation. All choices can be found here:
# http://www.i18nguy.com/unicode/language-identifiers.html
LANGUAGE_CODE = 'en-us'

SITE_ID = 1

# If you set this to False, Django will make some optimizations so as not
# to load the internationalization machinery.
USE_I18N = True

# If you set this to False, Django will not format dates, numbers and
# calendars according to the current locale.
USE_L10N = True

# If you set this to False, Django will not use timezone-aware datetimes.
USE_TZ = True

# Absolute filesystem path to the directory that will hold user-uploaded files.
# Example: "/home/media/media.lawrence.com/media/"
MEDIA_ROOT = 'media'

# URL that handles the media served from MEDIA_ROOT. Make sure to use a
# trailing slash.
# Examples: "http://media.lawrence.com/media/", "http://example.com/media/"
MEDIA_URL = 'd1eyn4cjl5vzx0.cloudfront.net'

# Absolute path to the directory static files should be collected to.
# Don't put anything in this directory yourself; store your static files
# in apps' "static/" subdirectories and in STATICFILES_DIRS.
# Example: "/home/media/media.lawrence.com/static/"
STATIC_ROOT = 'static'

# URL prefix for static files.
# Example: "http://media.lawrence.com/static/"
STATIC_URL = 'd280kzug7l5rug.cloudfront.net'

# Additional locations of static files
STATICFILES_DIRS = (
    # Put strings here, like "/home/html/static" or "C:/www/django/static".
    # Always use forward slashes, even on Windows.
    # Don't forget to use absolute paths, not relative paths.
)

# List of finder classes that know how to find static files in
# various locations.
STATICFILES_FINDERS = (
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
    'django.contrib.staticfiles.finders.DefaultStorageFinder',
)

# Make this unique, and don't share it with anybody.
SECRET_KEY = '2vhexv#0!u4eeyai9jluz8g&h7=815op$8nwa)5+=2m$hl61cu'

# List of callables that know how to import templates from various sources.
TEMPLATE_LOADERS = (
    'django.template.loaders.filesystem.Loader',
    'django.template.loaders.app_directories.Loader',
    'django.template.loaders.eggs.Loader',
)

MIDDLEWARE_CLASSES = (
    'django.middleware.common.CommonMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    # Uncomment the next line for simple clickjacking protection:
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
)

ROOT_URLCONF = 'DoneBox.urls'

# Python dotted path to the WSGI application used by Django's runserver.
WSGI_APPLICATION = 'DoneBox.wsgi.application'

TEMPLATE_DIRS = (
    # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
    # Always use forward slashes, even on Windows.
    # Don't forget to use absolute paths, not relative paths.
)

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.sitemaps'
    'django.contrib.messages',
    'django.contrib.staticfiles',
    # Uncomment the next line to enable the admin:
    'django.contrib.admin',
    # Uncomment the next line to enable admin documentation:
    'django.contrib.admindocs',
    'main',
    'basic.blog',
    'contact_form',
    'django-registration',
    'django-ses',
    'django-storages',
    'dajax',
    'dajaxice',
    'addressbook',
)

# A sample logging configuration. The only tangible logging
# performed by this configuration is to send an email to
# the site admins on every HTTP 500 error when DEBUG=False.
# See http://docs.djangoproject.com/en/dev/topics/logging for
# more details on how to customize your logging configuration.
LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'filters': {
        'require_debug_false': {
            '()': 'django.utils.log.RequireDebugFalse'
        }
    },
    'handlers': {
        'mail_admins': {
            'level': 'ERROR',
            'filters': ['require_debug_false'],
            'class': 'django.utils.log.AdminEmailHandler'
        }
    },
    'loggers': {
        'django.request': {
            'handlers': ['mail_admins'],
            'level': 'ERROR',
            'propagate': True,
        },
        'django.db.backends': {
            'handlers': ['mail_admin'],
            'level': 'DEBUG',
            }
        }
    }

ACCOUNT_ACTIVATION_DAYS = 2
EMAIL_BACKEND = 'django_ses.SESBackend'
DEFAULT_FILE_STORAGE = 'storages.backends.s3boto.S3BotoStorage'
AWS_ACCESS_KEY_ID = '<snip>'
AWS_SECRET_ACCESS_KEY ='<snip>'
STATIC_FILES_BUCKET = "donebox-static"
MEDIA_FILES_BUCKET = "donebox-media"

そして私のrequirements.txt:

BeautifulSoup==3.2.1
Django==1.4.3
MySQL-python==1.2.4
argparse==1.2.1
boto==2.7.0
distribute==0.6.34
django-dajax==0.9.2
django-dajaxice==0.5.4.1
django-piston==0.2.3
django-registration==0.8
django-ses==0.4.1
django-storages==1.1.6
django-tagging==0.3.1
markup==0.2
python-dateutil==2.1
six==1.2.0
tweepy==1.13
wsgiref==0.1.2

更新: ./manage.py --help でスタック トレースが表示されるようになりました。

Traceback (most recent call last):
  File "./manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/Users/levicc00123/DoneBox/env/lib/python2.6/site-packages/django/core/management/__init__.py", line 443, in execute_from_comma
nd_line
    utility.execute()
  File "/Users/levicc00123/DoneBox/env/lib/python2.6/site-packages/django/core/management/__init__.py", line 380, in execute
    sys.stdout.write(self.main_help_text() + '\n')
  File "/Users/levicc00123/DoneBox/env/lib/python2.6/site-packages/django/core/management/__init__.py", line 231, in main_help_text
    for name, app in get_commands().iteritems():
  File "/Users/levicc00123/DoneBox/env/lib/python2.6/site-packages/django/core/management/__init__.py", line 101, in get_commands
    apps = settings.INSTALLED_APPS
  File "/Users/levicc00123/DoneBox/env/lib/python2.6/site-packages/django/utils/functional.py", line 184, in inner
    self._setup()
  File "/Users/levicc00123/DoneBox/env/lib/python2.6/site-packages/django/conf/__init__.py", line 42, in _setup
    self._wrapped = Settings(settings_module)
  File "/Users/levicc00123/DoneBox/env/lib/python2.6/site-packages/django/conf/__init__.py", line 93, in __init__
    mod = importlib.import_module(self.SETTINGS_MODULE)
  File "/Users/levicc00123/DoneBox/env/lib/python2.6/site-packages/django/utils/importlib.py", line 35, in import_module
    __import__(name)
  File "/Users/levicc00123/DoneBox/DoneBox/settings.py", line 16, in <module>
    'NAME': os.environ['RDS_DB_NAME'],
  File "/Users/levicc00123/DoneBox/env/lib64/python2.6/UserDict.py", line 22, in __getitem__
    raise KeyError(key)

この奇妙な問題に光を当てるかもしれないアイデアを誰かが持っていますか? あなたの時間と配慮していただきありがとうございます。

4

1 に答える 1

0

sqlallsql管理コマンドの両方が必要です。どちらも1.0から存在しているようですが、

$ ./manage.py help sqlall
...
Usage: manage.py sqlall [options] <appname appname ...>

Prints the CREATE TABLE, custom SQL and CREATE INDEX SQL statements
for the given model module name(s).
...

sqlそれらに含まれるコマンドを参照してください。

$ ./manage.py --help | grep sql
monitor (pid=16660): Starting change monitor.
    sql
    sqlall
    sqlclear
    sqlcustom
    sqlflush
    sqlindexes
    sqlinitialdata
    sqlreset
    sqlsequencereset
    sqlcreate
    sqldiff

どのバージョンのdjangoを使用していますか?-それは重要ではありません

$ ./manage.py shell
monitor (pid=16669): Starting change monitor.
Python 2.7.3 (default, Jan 15 2013, 12:25:59) 
[GCC 4.1.2 20080704 (Red Hat 4.1.2-48)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> import django
>>> django.VERSION
(1, 4, 3, 'final', 0)

コメントで指摘されているように、KeyErrorがあります。

  File "/Users/levicc00123/DoneBox/DoneBox/settings.py", line 16, in <module>
    'NAME': os.environ['RDS_DB_NAME'],
  File "/Users/levicc00123/DoneBox/env/lib64/python2.6/UserDict.py", line 22, in __getitem__
    raise KeyError(key)

これを回避するには、のgetメソッドを使用しos.environてデフォルト値を指定します。例えば:

os.environ.get('RDS_DB_NAME', "default value if not in environment")
于 2013-01-21T03:15:16.200 に答える