2016-11-17 80 views
1

我想使用現有的mssql數據庫。我用inspectdb命令,但它不工作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. 
+0

嗨請檢查分貝主機請使用IP或主機名稱 –

回答

1

問題出在settings.py文件中的數據庫設置中。它存在拼寫錯誤。

定義DB的設置是這樣的:

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

爲了更好的做法,只使用IP地址,主機'HOST': '102.35.140.54'

+0

其工作,但得到以下錯誤。 >>>命令: SELECT * FROM [NI_PI_BASE_MST],其中1 = 0 參數: [] #無法檢查表 'NI_PI_BUDGET_MST' #錯誤是: '異常發生'(-2147352567,(0, 'Microsoft SQL Server Native Client 11.0','無效的對象名稱'NI_PI_BUDGET_MST'「,None,0,-2147217865),None)<<<< –

+0

@RohitKhadatkar我沒有任何有關您的數據庫的信息。無法幫助你解決這個錯誤。也許你可以爲此提出一個單獨的問題。 –