我正在使用django和mssql。我已经有了一个现有的数据库,并希望为该数据库中的表创建django模型。
我遵循了这个关于inspectdb的django book指令。
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:
[]
但我不知道该改变什么。有什么建议吗?
答案 0 :(得分:0)
https://github.com/denisenkom/django-sqlserver/issues/3
显然它是django ms-sql包中存在的一个未解决的问题。
如果有人遇到同样的问题,请制作自己的模型或look at the workaround recommended at the end of this issue