1

我正在尝试使用 django-pyodbc 版本连接到外部 SQL Server Express 数据库:this github link但是当我运行manage.py shell以检查是否可以执行 ORM 命令时,我不断收到此错误

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)

我的 settings.py 有这个:

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"
}

我完全不知道我应该做什么,所以欢迎所有想法。基本上我想要的是能够使用我制作的一个小应用程序与 SQL Server 数据库交互,同时能够使用普通的 DJango ORM 命令代替 pyodbc 连接字符串(顺便说一句,使用 pyodbc,我可以连接到SQL Server 数据库没有问题)

4

1 回答 1

2

在我看来,您正在使用http://code.google.com/p/django-pyodbc/上的 django-pyodbc 的旧仓库

确保彻底卸载旧版本,然后重新安装

pip uninstall sql-server.pyodbc
pip install git+https://github.com/avidal/django-pyodbc.git
于 2013-01-28T14:16:40.813 回答