2013-07-18 25 views
2

我做了什麼的Heroku上https://devcenter.heroku.com/articles/django錯誤地配置:settings.DATABASES配置不正確。請提供ENGINE值。檢查設置文檔瞭解更多信息

指定但是,當我運行heroku run python manage.py syncdb

其說ImproperlyConfigured: settings.DATABASES is improperly configured. Please supply the ENGINE value. Check settings documentation for more details.

這是我的settings.py文件看起來像。我嘗試了所有的解決方案,我找不到任何幫助

django_synapse項目的Django設置。

DEBUG = True 
TEMPLATE_DEBUG = DEBUG 

ADMINS = (
    # ('Your Name', '[email protected]'), 
) 

MANAGERS = ADMINS 

DATABASES = { 
    'default': { 
     'ENGINE': 'django.db.backends.', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'. 
     'NAME': '',      # Or path to database file if using sqlite3. 
     # The following settings are not used with sqlite3: 
     'USER': '', 
     'PASSWORD': '', 
     'HOST': '',      # Empty for localhost through domain sockets or '127.0.0.1' for localhost through TCP. 
     'PORT': '',      # Set to empty string for default. 
    } 
} 

# Hosts/domain names that are valid for this site; required if DEBUG is False 
# See https://docs.djangoproject.com/en/1.5/ref/settings/#allowed-hosts 
ALLOWED_HOSTS = [] 

# 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/Chicago' 

# 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: "/var/www/example.com/media/" 
MEDIA_ROOT = '' 

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

# 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: "/var/www/example.com/static/" 
STATIC_ROOT = '' 

# URL prefix for static files. 
# Example: "http://example.com/static/", "http://static.example.com/" 
STATIC_URL = '/static/' 

# 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 = 'h4fm7a&92r1hxa$j&u*7j)61-o2#17k)zy9fncz+7=usn74v%2' 

# 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 = 'django_synapse.urls' 

# Python dotted path to the WSGI application used by Django's runserver. 
WSGI_APPLICATION = 'django_synapse.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.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', 
) 

# 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, 
     }, 
    } 
} 

# Parse database configuration from $DATABASE_URL 
import dj_database_url 
DATABASES['default'] = dj_database_url.config() 

# Honor the 'X-Forwarded-Proto' header for request.is_secure() 
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https') 

# Allow all host headers 
ALLOWED_HOSTS = ['*'] 

# Static asset configuration 
import os 
BASE_DIR = os.path.dirname(os.path.abspath(__file__)) 
STATIC_ROOT = 'staticfiles' 
STATIC_URL = '/static/' 

STATICFILES_DIRS = (
    os.path.join(BASE_DIR, 'static'), 
) 

回答

2

您是否嘗試過https://devcenter.heroku.com/articles/django#django-settings文檔中的內容?

import dj_database_url 
DATABASES['default'] = dj_database_url.config() 

它說

Django配置

接下來,配置Heroku的環境中的應用,包括 Heroku的Postgres數據庫。 dj-database-url模塊將解析DATABASE_URL環境變量的 值,並將它們轉換爲Django可以理解的東西 。

確保 'DJ-數據庫URL' 是你的要求的文件,然後添加 以下到您的settings.py文件的底部:

settings.py

# Parse database configuration from $DATABASE_URL 
import dj_database_url 
DATABASES['default'] = dj_database_url.config() 

# Honor the 'X-Forwarded-Proto' header for request.is_secure() 
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https') 

# Allow all host headers 
ALLOWED_HOSTS = ['*'] 

# Static asset configuration 
import os 
BASE_DIR = os.path.dirname(os.path.abspath(__file__)) 
STATIC_ROOT = 'staticfiles' 
STATIC_URL = '/static/' 

STATICFILES_DIRS = (
    os.path.join(BASE_DIR, 'static'), 
) 
+0

蘇丹,我甚至不得不定義用於heroku的DATABASE_URL環境變量?這個價值是什麼? – Jonathan

+0

哦,我現在看到它!但是,它的價值是什麼?我很困惑。應該是一個具體的價值還是我選擇它? – Jonathan

+1

想通了!添加了一個數據庫,並查看了heroku配置以獲取URL。謝謝! :) – Jonathan

0

您尚未定義任何數據庫信息。
你的數據庫部分應該是這個樣子:

DATABASES = { 
    'default': { 
     'ENGINE': 'django.db.backends.postgresql_psycopg2', 
     'NAME': 'your_db_name',      
     'USER': 'your_db_user_name', 
     'PASSWORD': 'your_password', 
     'HOST': 'ec2-23-21-133-106.compute-1.amazonaws.com', # Or something like this 
     'PORT': '5432',      
    } 
} 
5

兩個蘇丹和喬是正確的,如果你把它們放在一起,並深入一點它的作品,我只是想更清晰一點與攤開來此外,這幫助了我。在Heroku的網站,這些instructions解釋如何設置它包括哪些蘇丹提到,增加此部分的settings.py:

# Parse database configuration from $DATABASE_URL 
import dj_database_url 
DATABASES['default'] = dj_database_url.config() 

# Honor the 'X-Forwarded-Proto' header for request.is_secure() 
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https') 

# Allow all host headers 
ALLOWED_HOSTS = ['*'] 

# Static asset configuration 
import os 
BASE_DIR = os.path.dirname(os.path.abspath(__file__)) 
STATIC_ROOT = 'staticfiles' 
STATIC_URL = '/static/' 

STATICFILES_DIRS = (
    os.path.join(BASE_DIR, 'static'), 
) 

然後,(以及這些指令不提)在您的Heroku帳戶去您的數據庫部分並選擇您想要使用的數據庫。轉到「連接設置」(兩個箭頭朝相反的方向)並選擇Django選項。該代碼應該是什麼樣子喬提到:

DATABASES = { 
    'default': { 
     'ENGINE': 'django.db.backends.postgresql_psycopg2', 
     'NAME': 'your_db_name', 
     'HOST': 'your_host', 
     'PORT': '5432',      
     'USER': 'your_db_user_name', 
     'PASSWORD': 'your_password',        
    } 
} 

在您的settings.py文件的底部粘貼此並同步您的數據庫。

2

您正在定義DATABASES = {'default': {... }}兩次。

解決方案:

如果您使用Heroku的服務,如果你試圖連接到外部數據庫服務器評論這兩個數據庫,然後使用這個

進口dj_database_url

DATABASES['default'] = dj_database_url.config() 

上面的線和使用這個

DATABASES = { 
    'default': { 
     'ENGINE': 'django.db.backends.', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'. 
     'NAME': '',      # Or path to database file if using sqlite3. 
     # The following settings are not used with sqlite3: 
     'USER': '', 
     'PASSWORD': '', 
     'HOST': '',      # Empty for localhost through domain sockets or '127.0.0.1' for localhost through TCP. 
     'PORT': '',      # Set to empty string for default. 
    } 
} 
相關問題