user5586747
user5586747

Reputation:

Error on inspectdb model creation django

I am using django with mssql. I already have a existing database and want to create django model for the tables in that database.

I followed this django book instruction for inspectdb.

http://django-book.readthedocs.io/en/latest/chapter18.html

When i enter the command

python manage.py inspectdb > interface/models.py

I get following error

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:
[]

I cannot figure out how to debug this issue. It seems there is some hint on last lines of error

Command:
SELECT * FROM [Attribute] where 1=0
Parameters:
[]

but i don't know what to change. Any suggestion?

Upvotes: 0

Views: 793

Answers (1)

user5586747
user5586747

Reputation:

https://github.com/denisenkom/django-sqlserver/issues/3

Apparently it's one of the open issues present in the django ms-sql package.

If anyone is having the same trouble, make your own models or look at the workaround recommended at the end of this issue

Upvotes: 0

Related Questions