inspectdb命令,但它不起作用

时间:2016-11-17 12:53:56

标签: sql-server django python-3.x django-models

我想使用现有的mssql数据库。我使用了inspectdb命令,但它没有工作

这是我的数据库配置:

DATABASES = {
    'default': {
    'NAME': 'xxxx',
    'ENGINE': 'sqlserver_ado',
    'HOST': '102.35.140.54\SQLEXPRESS',
    'USER': 'xxxx',
    'PASSWORD': 'xxxxx',
    'PORT' : '1434',
    'OPTIONS': {
        'provider': 'SQLNCLI11',
              }
}
}

我解雇python manage.py inspectdb并收到错误。

D:\Python_Workspace\oracle>python manage.py migrate
Traceback (most recent call last):
  File "manage.py", line 22, in <module>
    execute_from_command_line(sys.argv)
  File "C:\Python35\lib\site-packages\django\core\management\__init__.py", line 367, in execute_from_command_line
    utility.execute()
  File "C:\Python35\lib\site-packages\django\core\management\__init__.py", line 359, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "C:\Python35\lib\site-packages\django\core\management\base.py", line 294, in run_from_argv
    self.execute(*args, **cmd_options)
  File "C:\Python35\lib\site-packages\django\core\management\base.py", line 345, in execute
    output = self.handle(*args, **options)
  File "C:\Python35\lib\site-packages\django\core\management\commands\migrate.py", line 83, in handle
    executor = MigrationExecutor(connection, self.migration_progress_callback)
  File "C:\Python35\lib\site-packages\django\db\migrations\executor.py", line 20, in __init__
    self.loader = MigrationLoader(self.connection)
  File "C:\Python35\lib\site-packages\django\db\migrations\loader.py", line 52, in __init__
    self.build_graph()
  File "C:\Python35\lib\site-packages\django\db\migrations\loader.py", line 203, in build_graph
    self.applied_migrations = recorder.applied_migrations()
  File "C:\Python35\lib\site-packages\django\db\migrations\recorder.py", line 65, in applied_migrations
    self.ensure_schema()
  File "C:\Python35\lib\site-packages\django\db\migrations\recorder.py", line 52, in ensure_schema
    if self.Migration._meta.db_table in self.connection.introspection.table_names(self.connection.cursor()):
  File "C:\Python35\lib\site-packages\django\db\backends\base\base.py", line 231, in cursor
    cursor = self.make_debug_cursor(self._cursor())
  File "C:\Python35\lib\site-packages\django\db\backends\base\base.py", line 204, in _cursor
    self.ensure_connection()
  File "C:\Python35\lib\site-packages\django\db\backends\base\base.py", line 199, in ensure_connection
    self.connect()
  File "C:\Python35\lib\site-packages\django\db\backends\base\base.py", line 170, in connect
    conn_params = self.get_connection_params()
  File "C:\Python35\lib\site-packages\sqlserver_ado\base.py", line 225, in get_connection_params
    'connection_string': make_connection_string(settings_dict),
  File "C:\Python35\lib\site-packages\sqlserver_ado\base.py", line 56, in make_connection_string
    raise ImproperlyConfigured("When using DATABASE PORT, DATABASE HOST must be an IP address.")
django.core.exceptions.ImproperlyConfigured: When using DATABASE PORT, DATABASE HOST must be an IP address.

1 个答案:

答案 0 :(得分:1)

问题出在settings.py文件中的数据库设置中。这是一个拼写错误。

像这样定义数据库设置:

DATABASES = {
    'default': {
    'NAME': 'xxxx',
    'ENGINE': 'sqlserver_ado',
    'HOST': '102.35.140.54',
    'USER': 'xxxx',
    'PASSWORD': 'xxxxx',
    'PORT' : '1434',
    'OPTIONS': {
        'provider': 'SQLNCLI11',
              }
        }
}

为了更好的做法,只使用HOST中的IP地址作为'HOST':'102.35.140.54'

相关问题