Django inspectdb错误

时间:2013-08-22 03:53:39

标签: django

如果试着从mysite的主目录运行django-admin.py inspectdb命令,我收到以下错误。

错误

Traceback (most recent call last):
  File "C:\_Data\MyFolder\Python\Scripts\django-admin.py", line 5, in <module> management.execute_from_command_line()
  File "C:\_Data\MyFolder\Python\lib\site-packages\django\core\management\__init__.py", line 453, in execute_from_command_line utility.execute()
  File "C:\_Data\MyFolder\Python\lib\site-packages\django\core\management\__init__.py", line 392, in execute self.fetch_command(subcommand).run_from_argv(self.argv)
  File "C:\_Data\MyFolder\Python\lib\site-packages\django\core\management\__init__.py", line 272, in fetch_command klass = load_command_class(app_name, subcommand)
  File "C:\_Data\MyFolder\Python\lib\site-packages\django\core\management\__init__.py", line 77, in load_command_class module = import_module('%s.management.commands.%s' % (app_name, name))
  File "C:\_Data\MyFolder\Python\lib\site-packages\django\utils\importlib.py", line 35, in import_module __import__(name)
  File "C:\_Data\MyFolder\Python\lib\site-packages\django\core\management\commands\inspectdb.py", line 8, in <module> from django.db import connections, DEFAULT_DB_ALIAS
  File "C:\_Data\MyFolder\Python\lib\site-packages\django\db\__init__.py", line 11, in <module> if settings.DATABASES and DEFAULT_DB_ALIAS not in settings.DATABASES:
  File "C:\_Data\MyFolder\Python\lib\site-packages\django\conf\__init__.py", line53, in __getattr__ self._setup(name)
  File "C:\_Data\MyFolder\Python\lib\site-packages\django\conf\__init__.py", line46, 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.

我的settings.py文件定义了oracle DB设置:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.oracle', 
        'NAME': 'MyDB',
        'USER': 'MyUser',
        'PASSWORD': 'MyPSW',
        'HOST': 'Host',
        'PORT': '1521',
    }
}

为什么系统无法识别数据库设置?

2 个答案:

答案 0 :(得分:0)

从各种博客中,以下解决了这个问题:

环境变量:

DJANGO_SETTINGS_MODULEmysite.settings

swgi.py文件

import os,sys 
sys.path.append("C:\\Path\\Where\\settings.py\\file\\Resides")
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings")

manage.py

#!/usr/bin/env python
import os,sys
if __name__ == "__main__":    
    sys.path.append("C:\\Path\\Where\\settings.py\\file\\Resides")
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings")

启动开发服务器,然后在单独的窗口中运行django-admin.py inspectdb

答案 1 :(得分:0)

尝试使用 python manage.py inspectdb 相反,为我工作