1

虽然尝试从 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',
    }
}

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

4

2 回答 2

0

Taken from various blogs , the following resolved the issue :

Environment Variable :

DJANGO_SETTINGS_MODULE : mysite.settings

swgi.py file

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")

Start the dev server and then run django-admin.py inspectdb on a s separate window

于 2013-08-22T21:50:46.230 回答
0

尝试使用 python manage.py inspectdb 代替,为我工作

于 2017-03-31T23:50:33.007 回答