我正在使用 django 和 mssql。我已经有一个现有的数据库,并想为该数据库中的表创建 django 模型。
我按照这个 django book 指令进行了inspectdb。
http://django-book.readthedocs.io/en/latest/chapter18.html
当我输入命令
python manage.py inspectdb > interface/models.py
我收到以下错误
Traceback (most recent call last):
File "C:\Users\Suman Nepal\Anaconda3\lib\site-packages\sqlserver_ado\dbapi.py", line 547, i
n _execute_command
recordset = self.cmd.Execute()
File "<COMObject ADODB.Command>", line 3, in Execute
File "C:\Users\Suman Nepal\Anaconda3\lib\site-packages\win32com\client\dynamic.py", line 28
7, in _ApplyTypes_
result = self._oleobj_.InvokeTypes(*(dispid, LCID, wFlags, retType, argTypes) + args)
pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, 'Microsoft SQL Server Native C
lient 11.0', "Invalid object name 'Attribute'.", None, 0, -2147217865), None)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\Suman Nepal\Anaconda3\lib\site-packages\django\db\backends\utils.py", line 6
2, in execute
return self.cursor.execute(sql)
File "C:\Users\Suman Nepal\Anaconda3\lib\site-packages\sqlserver_ado\dbapi.py", line 647, i
n execute
self._execute_command()
File "C:\Users\Suman Nepal\Anaconda3\lib\site-packages\sqlserver_ado\dbapi.py", line 558, i
n _execute_command
self._raiseCursorError(klass, _message)
File "C:\Users\Suman Nepal\Anaconda3\lib\site-packages\sqlserver_ado\dbapi.py", line 488, i
n _raiseCursorError
eh(self.connection, self, errorclass, errorvalue)
File "C:\Users\Suman Nepal\Anaconda3\lib\site-packages\sqlserver_ado\dbapi.py", line 103, i
n standardErrorHandler
raise errorclass(errorvalue)
sqlserver_ado.dbapi.DatabaseError: (-2147352567, 'Exception occurred.', (0, 'Microsoft SQL Se
rver Native Client 11.0', "Invalid object name 'Attribute'.", None, 0, -2147217865), None)
Command:
SELECT * FROM [Attribute] where 1=0
Parameters:
[]
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "manage.py", line 15, in <module>
execute_from_command_line(sys.argv)
File "C:\Users\Suman Nepal\Anaconda3\lib\site-packages\django\core\management\__init__.py",
line 338, in execute_from_command_line
utility.execute()
File "C:\Users\Suman Nepal\Anaconda3\lib\site-packages\django\core\management\__init__.py",
line 330, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Users\Suman Nepal\Anaconda3\lib\site-packages\django\core\management\base.py", lin
e 390, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Users\Suman Nepal\Anaconda3\lib\site-packages\django\core\management\base.py", lin
e 441, in execute
output = self.handle(*args, **options)
File "C:\Users\Suman Nepal\Anaconda3\lib\site-packages\django\core\management\commands\insp
ectdb.py", line 25, in handle
for line in self.handle_inspection(options):
File "C:\Users\Suman Nepal\Anaconda3\lib\site-packages\django\core\management\commands\insp
ectdb.py", line 76, in handle_inspection
for row in connection.introspection.get_table_description(cursor, table_name):
File "C:\Users\Suman Nepal\Anaconda3\lib\site-packages\sqlserver_ado\introspection.py", lin
e 101, in get_table_description
cursor.execute("SELECT * FROM [%s] where 1=0" % (table_name))
File "C:\Users\Suman Nepal\Anaconda3\lib\site-packages\django\db\backends\utils.py", line 79, in e
xecute
return super(CursorDebugWrapper, self).execute(sql, params)
File "C:\Users\Suman Nepal\Anaconda3\lib\site-packages\django\db\backends\utils.py", line 64, in e
xecute
return self.cursor.execute(sql, params)
File "C:\Users\Suman Nepal\Anaconda3\lib\site-packages\django\db\utils.py", line 97, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "C:\Users\Suman Nepal\Anaconda3\lib\site-packages\django\utils\six.py", line 658, in reraise
raise value.with_traceback(tb)
File "C:\Users\Suman Nepal\Anaconda3\lib\site-packages\django\db\backends\utils.py", line 62, in e
xecute
return self.cursor.execute(sql)
File "C:\Users\Suman Nepal\Anaconda3\lib\site-packages\sqlserver_ado\dbapi.py", line 647, in execu
te
self._execute_command()
File "C:\Users\Suman Nepal\Anaconda3\lib\site-packages\sqlserver_ado\dbapi.py", line 558, in _exec
ute_command
self._raiseCursorError(klass, _message)
File "C:\Users\Suman Nepal\Anaconda3\lib\site-packages\sqlserver_ado\dbapi.py", line 488, in _rais
eCursorError
eh(self.connection, self, errorclass, errorvalue)
File "C:\Users\Suman Nepal\Anaconda3\lib\site-packages\sqlserver_ado\dbapi.py", line 103, in stand
ardErrorHandler
raise errorclass(errorvalue)
django.db.utils.DatabaseError: (-2147352567, 'Exception occurred.', (0, 'Microsoft SQL Server Native
Client 11.0', "Invalid object name 'Attribute'.", None, 0, -2147217865), None)
Command:
SELECT * FROM [Attribute] where 1=0
Parameters:
[]
我不知道如何调试这个问题。最后几行错误似乎有一些提示
Command:
SELECT * FROM [Attribute] where 1=0
Parameters:
[]
但我不知道要改变什么。有什么建议吗?