Question

I'm trying to connect to an external SQL Server Express database using the django-pyodbc version at: this github link but I keep getting this error when I run manage.py shell to check if I can execute come ORM commands

Traceback (most recent call last):
File "manage.py", line 10, in <module>
  execute_from_command_line(sys.argv)
File "/usr/local/lib/python2.7/site-packages/django/core/management/__init__.py", line   443, in execute_from_command_line
  utility.execute()
File "/usr/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 382, in execute
  self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python2.7/site-packages/django/core/management/base.py", line 196, in run_from_argv
  self.execute(*args, **options.__dict__)
File "/usr/local/lib/python2.7/site-packages/django/core/management/base.py",line 232, in execute
  output = self.handle(*args, **options)
File "/usr/local/lib/python2.7/site-packages/django/core/management/base.py",line 371, in handle
  return self.handle_noargs(**options)
File "/usr/local/lib/python2.7/site-packages/django/core/management/commands/shell.py", line 45, in handle_noargs
  from django.db.models.loading import get_models
File "/usr/local/lib/python2.7/site-packages/django/db/__init__.py", line 40, in <module>
  backend = load_backend(connection.settings_dict['ENGINE'])
File "/usr/local/lib/python2.7/site-packages/django/db/__init__.py", line 34, in __getattr__
  return getattr(connections[DEFAULT_DB_ALIAS], item)
File "/usr/local/lib/python2.7/site-packages/django/db/utils.py", line 93, in __getitem__
  conn = backend.DatabaseWrapper(db, alias)
File "/usr/local/lib/python2.7/site-packages/sql_server/pyodbc/base.py", line 133, in __init__
  self.ops = DatabaseOperations(self)
File "/usr/local/lib/python2.7/site-packages/sql_server/pyodbc/operations.py", line 10, in __init__
  super(DatabaseOperations, self).__init__()
  TypeError: __init__() takes exactly 2 arguments (1 given)

My settings.py has this:

DATABASES = {
    'default': {
       'ENGINE': 'sql_server.pyodbc',
       'NAME': 'DBName',
       'HOST': '192.168.29.1',
       'USER': 'user',
       'PASSWORD': 'pswd',
       'PORT': 1433,
    }
}

DATABASE_OPTIONS = {
    'driver': '/usr/local/lib/libtdsodbc.so',
    'dsn': 'FreeTDS',
    'extra_params': "TDS_VERSION=8.0"
}

I'm completely at a loss as to what I'm supposed to do, so all ideas are welcome. Essentially what I want is to be able to use a small app I've made to interface with the SQL Server database, while being able to use normal DJango ORM commands inplace of pyodbc connection strings (and BTW using pyodbc, I can connect to the SQL Server database without an issue)

Was it helpful?

Solution

it seem to me that you are using the old repo for django-pyodbc at http://code.google.com/p/django-pyodbc/

make sure to cleanly uninstall the old version and then reinstall

pip uninstall sql-server.pyodbc
pip install git+https://github.com/avidal/django-pyodbc.git
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top