所以我最近根据此处找到的指南转换了我的 django 数据库设置以使用 settings.ini 文件
我的问题是,现在 syncdb 已停止为新部署工作:
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/usr/lib/python2.7/site-packages/django/core/management/__init__.py", line 399, in execute_from_command_line
utility.execute()
File "/usr/lib/python2.7/site-packages/django/core/management/__init__.py", line 392, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/lib/python2.7/site-packages/django/core/management/base.py", line 242, in run_from_argv
self.execute(*args, **options.__dict__)
File "/usr/lib/python2.7/site-packages/django/core/management/base.py", line 285, in execute
output = self.handle(*args, **options)
File "/usr/lib/python2.7/site-packages/django/core/management/base.py", line 415, in handle
return self.handle_noargs(**options)
File "/usr/lib/python2.7/site-packages/django/core/management/commands/syncdb.py", line 57, in handle_noargs
cursor = connection.cursor()
File "/usr/lib/python2.7/site-packages/django/db/backends/__init__.py", line 160, in cursor
cursor = self.make_debug_cursor(self._cursor())
File "/usr/lib/python2.7/site-packages/django/db/backends/dummy/base.py", line 15, in complain
raise ImproperlyConfigured("settings.DATABASES is improperly configured. "
django.core.exceptions.ImproperlyConfigured: settings.DATABASES is improperly configured. Please supply the ENGINE value. Check settings documentation for more details.
设置.ini:
[database]
DATABASE_ENGINE: django.db.backends.postgresql_psycopg2
DATABASE_NAME: postgres
DATABASE_USER: postgres
DATABASE_PASSWORD:
DATABASE_HOST: db
DATABASE_PORT: 5432
设置.py:
import os
import sys
from ConfigParser import RawConfigParser
config = RawConfigParser()
config.read('settings.ini')
DEBUG = bool(os.environ.get('DEBUG', False))
DEBUG_TOOLBAR = bool(os.environ.get('DEBUG_TOOLBAR', False))
TEMPLATE_DEBUG = bool(os.environ.get('TEMPLATE_DEBUG', False))
#Database Config is pulled from the config file
DATABASE_USER = config.get('database', 'DATABASE_USER')
DATABASE_PASSWORD = config.get('database', 'DATABASE_PASSWORD')
DATABASE_HOST = config.get('database', 'DATABASE_HOST')
DATABASE_PORT = config.get('database', 'DATABASE_PORT')
DATABASE_ENGINE = config.get('database', 'DATABASE_ENGINE')
DATABASE_NAME = config.get('database', 'DATABASE_NAME')
我最初开始沿着这条路走,因此我们的服务可以在不同的站点上运行,并具有易于配置的设置管理文件。它还试图使开发环境变得轻松,因为配置不再必须在代码库中,因为它可以存储在其他地方。
我是否错误地实现了某些东西,或者我是否遇到了问题 22,这种类型的设置更改仅在数据库已经同步的情况下才有效?
这是在 Django 1.6.5 中
编辑
我忘了提到python manage.py diffsettings
返回预期值,所以我知道 manage.py 可以正确访问和解释 settings.ini 文件。
DATABASE_ENGINE = 'django.db.backends.postgresql_psycopg2' ###
DATABASE_HOST = 'db' ###
DATABASE_NAME = 'postgres' ###
DATABASE_PASSWORD = '' ###
DATABASE_PORT = '5432' ###
DATABASE_USER = 'postgres' ###