Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

django-admin inspectdb #99

Open
backbohne opened this issue Sep 17, 2015 · 6 comments
Open

django-admin inspectdb #99

backbohne opened this issue Sep 17, 2015 · 6 comments

Comments

@backbohne
Copy link

Not sure if this is realy implemeted and tested. Got the following exception:

django-admin inspectdb --database=mymssqlserver

# This is an auto-generated Django model module.
# You'll have to do the following manually to clean this up:
#   * Rearrange models' order
#   * Make sure each model has one field with primary_key=True
#   * Remove `managed = False` lines if you wish to allow Django to create, modify, and delete the table
# Feel free to rename the models, but don't rename db_table values or field names.
#
# Also note: You'll have to insert the output of 'django-admin sqlcustom [app_label]'
# into your database.
from __future__ import unicode_literals

from django.db import models
Traceback (most recent call last):
  File "/opt/deep-python-lib/bin/django-admin", line 11, in <module>
    sys.exit(execute_from_command_line())
  File "/opt/deep-python-lib/lib/python2.7/site-packages/django/core/management/__init__.py", line 338, in execute_from_command_line
    utility.execute()
  File "/opt/deep-python-lib/lib/python2.7/site-packages/django/core/management/__init__.py", line 330, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/opt/deep-python-lib/lib/python2.7/site-packages/django/core/management/base.py", line 393, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/opt/deep-python-lib/lib/python2.7/site-packages/django/core/management/base.py", line 444, in execute
    output = self.handle(*args, **options)
  File "/opt/deep-python-lib/lib/python2.7/site-packages/django/core/management/commands/inspectdb.py", line 25, in handle
    for line in self.handle_inspection(options):
  File "/opt/deep-python-lib/lib/python2.7/site-packages/django/core/management/commands/inspectdb.py", line 55, in handle_inspection
    for table_name in connection.introspection.table_names(cursor):
  File "/opt/deep-python-lib/lib/python2.7/site-packages/django/db/backends/base/introspection.py", line 58, in table_names
    return get_names(cursor)
  File "/opt/deep-python-lib/lib/python2.7/site-packages/django/db/backends/base/introspection.py", line 53, in get_names
    return sorted(ti.name for ti in self.get_table_list(cursor)
  File "/opt/deep-python-lib/lib/python2.7/site-packages/django/db/backends/base/introspection.py", line 54, in <genexpr>
    if include_views or ti.type == 't')
AttributeError: 'unicode' object has no attribute 'type'

A short look into django/db/backends/base/introspection.py pointed out that get_table_list()
should return a list of objects with attributes like name and type, but django-pyodbc's get_table_list() returns a list of table name unicodes.

@danlmyers
Copy link

I am getting very similar error when just trying to do a runserver:
python manage.py runserver

File "/usr/lib/python2.7/site-packages/django/utils/autoreload.py", line 225, in wrapper
fn(_args, *_kwargs)
File "/usr/lib/python2.7/site-packages/django/core/management/commands/runserver.py", line 112, in inner_run
self.check_migrations()
File "/usr/lib/python2.7/site-packages/django/core/management/commands/runserver.py", line 164, in check_migrations
executor = MigrationExecutor(connections[DEFAULT_DB_ALIAS])
File "/usr/lib/python2.7/site-packages/django/db/migrations/executor.py", line 19, in init
self.loader = MigrationLoader(self.connection)
File "/usr/lib/python2.7/site-packages/django/db/migrations/loader.py", line 47, in init
self.build_graph()
File "/usr/lib/python2.7/site-packages/django/db/migrations/loader.py", line 182, in build_graph
self.applied_migrations = recorder.applied_migrations()
File "/usr/lib/python2.7/site-packages/django/db/migrations/recorder.py", line 59, in applied_migrations
self.ensure_schema()
File "/usr/lib/python2.7/site-packages/django/db/migrations/recorder.py", line 49, in ensure_schema
if self.Migration._meta.db_table in self.connection.introspection.table_names(self.connection.cursor()):
File "/usr/lib/python2.7/site-packages/django/db/backends/base/introspection.py", line 58, in table_names
return get_names(cursor)
File "/usr/lib/python2.7/site-packages/django/db/backends/base/introspection.py", line 53, in get_names
return sorted(ti.name for ti in self.get_table_list(cursor)
File "/usr/lib/python2.7/site-packages/django/db/backends/base/introspection.py", line 54, in
if include_views or ti.type == 't')
AttributeError: 'unicode' object has no attribute 'type'

@RossRogers
Copy link
Contributor

Can you guys post SSCCEs, specify the versions of all your packages with pip freeze, and specify the vendor and version of the database you're connecting to?

@backbohne
Copy link
Author

  • Python 2.7.6
  • Microsoft SQL Server 2014 - 12.0.4213.0 (X64)
# pip freeze
alabaster==0.7.6
ansible==1.9.3
apt-xapian-index==0.45
apturl===0.4.1ubuntu4
Babel==1.3
BeautifulSoup==3.2.1
chardet==2.0.1
colorama==0.2.5
command-not-found==0.3
configglue==1.1.2
configobj==4.7.2
debtagshw==0.1
defer==1.0.6
defusedxml==0.4.1
deluge==1.3.6
dirspec==13.10
distro-info==0.12
Django==1.8.4
django-autocomplete-light==2.2.6
django-cors-headers==1.1.0
django-countries==3.3
django-filter==0.11.0
django-grappelli==2.7.1
django-model-utils==2.3.1
django-pyodbc==0.3.0
django-reversion==1.9.3
django-taggit==0.17.1
djangorestframework==2.4.6
djangorestframework-jsonp==1.0.2
djangorestframework-xml==1.2.0
djangorestframework-yaml==1.0.2
dnspython==1.11.1
docutils==0.11
docx==0.2.4
docx-xslt==1.0.4
dulwich==0.9.4
duplicity==0.6.23
ecdsa==0.13
enum==0.4.4
Fabric==1.10.2
feedparser==5.1.3
gevent==1.0.2
greenlet==0.4.9
grequests==0.2.0
hg-git==0.8.0
html5lib==0.999
httplib2==0.8
ida===2.2.10-20-g3077
IPy==0.83
jdcal==1.0
Jinja2==2.7.2
keyring==3.5
launchpadlib==1.10.2
lazr.restfulclient==0.13.3
lazr.uri==1.0.3
lockfile==0.8
lxml==3.4.4
Mako==0.9.1
Markdown==2.6.2
MarkupSafe==0.18
mechanize==0.2.5
mercurial==2.8.2
MySQL-python==1.2.3
nemo-emblems==0.0.1
numpy==1.8.2
oauth==1.0.1
oauthlib==0.6.1
oneconf==0.3.7.14.4.1
openpyxl==2.2.3
PAM==0.4.2
paramiko==1.15.2
pathlib==1.0.1
pexpect==3.1
Pillow==2.9.0
piston-mini-client==0.7.5
protobuf==2.5.0
pycrypto==2.6.1
pycups==1.9.66
pycurl==7.19.3
Pygments==2.0.2
pygobject==3.12.0
pyinotify==0.9.4
pyodbc==3.0.10
pyOpenSSL==0.13
pyserial==2.6
pysmbc==1.0.14.1
python-apt===0.9.3.5ubuntu1
python-dateutil==2.4.2
python-debian===0.1.21-nmu2ubuntu2
python-libtorrent==0.16.13
python-money==0.3.3
pytz==2015.6
pyxdg==0.25
PyYAML==3.11
reportlab==3.0
requests==2.7.0
roman==2.0.0
sessioninstaller==0.0.0
simplejson==3.8.0
six==1.9.0
snowballstemmer==1.2.0
South==1.0.2
Sphinx==1.3.1
sphinx-rtd-theme==0.1.8
sqlparse==0.1.10
system-service==0.1.6
tortoisehg==2.10
Twisted-Core==13.2.0
Twisted-Names==13.2.0
Twisted-Web==13.2.0
ubuntu-dev-tools==0.153
Unidecode==0.4.18
urllib3==1.7.1
uTidylib==0.2
uWSGI===2.1-dev-abac960
uwsgitop==0.8
vboxapi==1.0
wadllib==1.3.2
wheel==0.26.0
XlsxWriter==0.7.3
zope.interface==4.0.5

@danlmyers
Copy link

Python 2.7.5, Microsoft SQL server 2012

ansible==1.7.1
appdirs==1.4.0
astroid==1.3.8
Babel==2.1.1
backports.ssl-match-hostname==3.4.0.2
bash8==0.1.1
bzt==0.4.2
certifi==2015.9.6.2
chardet==2.0.1
click==5.1
cliff==1.15.0
cliff-tablib==1.1
cmd2==0.6.8
colorama==0.3.3
colorlog==2.6.0
configobj==4.7.2
cookies==2.2.1
coverage==3.7.1
cssselect==0.9.1
debtcollector==0.8.0
decorator==4.0.4
Django==1.8.4
django-pyodbc==0.3.0
djangorestframework==3.1.1
ethtool==0.8
flake8==2.4.0
freezegun==0.3.4
functools32==3.2.3.post2
gitlint==0.4.1
heighliner==0.5.1
httpie==0.9.2
httplib2==0.7.7
iniparse==0.4
ipdb==0.8.1
ipython==4.0.0
ipython-genutils==0.1.0
iso8601==0.1.10
javapackages==1.0.0
Jinja2==2.7.2
jsonpatch==1.11
jsonpointer==1.9
jsonschema==2.5.1
keystoneauth1==1.1.0
kitchen==1.1.1
livereload==2.4.0
logilab-common==1.0.2
lxml==3.4.4
M2Crypto==0.21.1
mando==0.3.3
Markdown==2.6.2
MarkupSafe==0.11
mccabe==0.3.1
mkdocs==0.14.0
mock==1.0.1
monotonic==0.3
msgpack-python==0.4.6
MySQL-python==1.2.3
netaddr==0.7.18
netifaces==0.10.4
newdawn-qa==2015.2.0.dev203
nose==1.3.7
os-client-config==1.7.5
oslo.config==2.4.0
oslo.i18n==2.6.0
oslo.serialization==1.9.0
oslo.utils==2.5.0
paramiko==1.11.3
path.py==8.1.1
pbr==1.8.0
pciutils==1.7.3
pep8==1.5.7
pexpect==3.3
pickleshare==0.5
prettytable==0.7.2
progressbar33==2.4
psutil==3.2.1
pyasn1==0.1.6
pycrypto==2.6.1
pycurl==7.19.0
pyflakes==0.8.1
Pygments==2.0.2
pygobject==3.8.2
pygpgme==0.3
pygraphviz==1.2
pyliblzma==0.5.3
pylint==1.4.4
pyodbc==3.0.10
pyOpenSSL==0.13.1
pyparsing==2.0.3
python-cinderclient==1.4.0
python-dateutil==2.4.2
python-dmidecode==3.10.13
python-glanceclient==1.1.0
python-keyczar==0.71rc0
python-keystoneclient==1.7.1
python-neutronclient==3.1.0
python-novaclient==2.30.0
python-openstackclient==1.7.0
pytz==2015.6
pyudev==0.15
pyxattr==0.5.1
PyYAML==3.11
radon==1.2.1
requests==2.7.0
responses==0.4.0
rhnlib==2.5.65
rhsm==1.10.12
selenium==2.47.3
sh==1.11
simplegeneric==0.8.1
simplejson==3.8.0
six==1.9.0
slip==0.4.0
slip.dbus==0.4.0
stevedore==1.8.0
tablib==0.10.0
tornado==4.2.1
traitlets==4.0.0
unicodecsv==0.14.1
urlgrabber==3.10
urwid==1.3.0
warlock==1.1.0
wrapt==1.10.5
yum-metadata-parser==1.1.4

I looked a bit into the introspection.py as well, get_table_list needs to return a list of TableInfo(), it does require an adjustment to the SQL Queries to get the TABLE_INFO to include with the TableInfo(). Then a SchemaEditor also needs to be included: https://docs.djangoproject.com/en/1.8/ref/schema-editor/

@stanep
Copy link

stanep commented Apr 29, 2016

Same issue with
Python 2.7.11
Microsoft SQL Server 2012

broke in the same place as above

@aronroberts
Copy link

aronroberts commented Jul 22, 2016

I am having the same issue with manage.py run server.

I created a new project with nothing in it and no other changes to make sure it wasn't something else causing the issue.

Platform: Mac OS X 10.11.5
Python 2.7.12

installed via macports:
unixODBC @2.3.2_0
freetds @1.00.9_0+odbc (active)

pip freeze output:

Django==1.8.14
django-pyodbc==0.3.0
pyodbc==3.0.10

DB Server: Microsoft SQL Server 2012

changes to settings.py:

DATABASES = {
   'default': {
       'ENGINE': "django_pyodbc",
       'HOST': "myhostname,1433",
       'USER': "myusername",
       'PASSWORD': "mypassword",
       'NAME': "mydbname",
       'OPTIONS': {
            'host_is_server': True,
       },
   }
}

Connections have been checked successfully with tsql and isql.

Stack trace:

Unhandled exception in thread started by <function wrapper at 0x108608d70>
Traceback (most recent call last):
  File "/Users/aron/DEV/VENVS/higgins-venv/lib/python2.7/site-packages/django/utils/autoreload.py", line 229, in wrapper
    fn(*args, **kwargs)
  File "/Users/aron/DEV/VENVS/higgins-venv/lib/python2.7/site-packages/django/core/management/commands/runserver.py", line 116, in inner_run
    self.check_migrations()
  File "/Users/aron/DEV/VENVS/higgins-venv/lib/python2.7/site-packages/django/core/management/commands/runserver.py", line 168, in check_migrations
    executor = MigrationExecutor(connections[DEFAULT_DB_ALIAS])
  File "/Users/aron/DEV/VENVS/higgins-venv/lib/python2.7/site-packages/django/db/migrations/executor.py", line 19, in __init__
    self.loader = MigrationLoader(self.connection)
  File "/Users/aron/DEV/VENVS/higgins-venv/lib/python2.7/site-packages/django/db/migrations/loader.py", line 47, in __init__
    self.build_graph()
  File "/Users/aron/DEV/VENVS/higgins-venv/lib/python2.7/site-packages/django/db/migrations/loader.py", line 191, in build_graph
    self.applied_migrations = recorder.applied_migrations()
  File "/Users/aron/DEV/VENVS/higgins-venv/lib/python2.7/site-packages/django/db/migrations/recorder.py", line 59, in applied_migrations
    self.ensure_schema()
  File "/Users/aron/DEV/VENVS/higgins-venv/lib/python2.7/site-packages/django/db/migrations/recorder.py", line 49, in ensure_schema
    if self.Migration._meta.db_table in self.connection.introspection.table_names(self.connection.cursor()):
  File "/Users/aron/DEV/VENVS/higgins-venv/lib/python2.7/site-packages/django/db/backends/base/introspection.py", line 58, in table_names
    return get_names(cursor)
  File "/Users/aron/DEV/VENVS/higgins-venv/lib/python2.7/site-packages/django/db/backends/base/introspection.py", line 53, in get_names
    return sorted(ti.name for ti in self.get_table_list(cursor)
  File "/Users/aron/DEV/VENVS/higgins-venv/lib/python2.7/site-packages/django/db/backends/base/introspection.py", line 54, in <genexpr>
    if include_views or ti.type == 't')
AttributeError: 'unicode' object has no attribute 'type'

@dlo dlo added the help wanted label Feb 1, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

6 participants