5

我正在尝试使用 django-mssql 通过 Django 1.4.2 连接到 MS SQL Server 2008 R2 这些是我的数据库设置:

DATABASE_ENGINE   = 'sqlserver_ado'
DATABASE_NAME     = 'dbtest'
DATABASE_USER     = 'App'
DATABASE_PASSWORD = '*********'
DATABASE_HOST     = 'localhost'
DATABASE_OPTIONS  =  {
            'provider': 'SQLNCLI10',
            'extra_params': 'DataTypeCompatibility=80;MARS Connection=True;',
        } 

DATABASES = {
  'default': {
    'ENGINE':   DATABASE_ENGINE,
    'NAME':     DATABASE_NAME,
    'USER':     DATABASE_USER,
    'PASSWORD': DATABASE_PASSWORD,
    'HOST':     DATABASE_HOST,
    'OPTIONS' : DATABASE_OPTIONS,
  },
}

这是我尝试同步数据库时遇到的错误

    Traceback (most recent call last):
  File "C:\Python27\DataSatellite\manage.py", line 11, in <module>
    execute_manager(settings)
  File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 459, in execute_manager
    utility.execute()
  File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 382, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "C:\Python27\lib\site-packages\django\core\management\base.py", line 196, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "C:\Python27\lib\site-packages\django\core\management\base.py", line 232, in execute
    output = self.handle(*args, **options)
  File "C:\Python27\lib\site-packages\django\core\management\base.py", line 371, in handle
    return self.handle_noargs(**options)
  File "C:\Python27\lib\site-packages\django\core\management\commands\syncdb.py", line 57, in handle_noargs
    cursor = connection.cursor()
  File "C:\Python27\lib\site-packages\django\db\backends\__init__.py", line 306, in cursor
    cursor = self.make_debug_cursor(self._cursor())
  File "C:\Python27\lib\site-packages\sqlserver_ado\base.py", line 193, in _cursor
    self.__connect()
  File "C:\Python27\lib\site-packages\sqlserver_ado\base.py", line 168, in __connect
    use_transactions=self.use_transactions,
  File "C:\Python27\lib\site-packages\sqlserver_ado\dbapi.py", line 151, in connect
    raise OperationalError(e, "Error opening connection: " + connection_string)
sqlserver_ado.dbapi.OperationalError: (AttributeError("'module' object has no attribute 'VARIANT'",), 'Error opening connection: DATA SOURCE=localhost;Initial Catalog=dbtest;UID=App;PWD=*********;PROVIDER=SQLNCLI10;MARS Connection=True;DataTypeCompatibility=80;MARS Connection=True;')
Finished "C:\Python27\DataSatellite\manage.py syncdb" execution.

我到处寻找,我似乎无法理解和解决问题。我希望有人能帮帮忙!谢谢!

编辑:

我已经创建了数据库。我还使用 django-pyodbc 连接到数据库,并且我已经成功地从数据库中读取和写入。但是 django-pyodbc 在我使用 Apache 时会出现问题,这就是我决定尝试 django-mssql 的原因。但是,我不明白它出现的错误。

我的 Django (1.4.2) 和 Python (2.7) 安装在 Windows 上运行,我使用的是 Apache 网络服务器。

4

1 回答 1

2

更新 pywin32 以构建 217 或更高版本。我在 stackoverflow 上发现了另一个具有相同问题的问题(关于另一个主题):

Python COM 服务器抛出“模块”对象没有属性“VARIANT”

于 2012-12-20T07:40:05.520 回答