我正在尝试使用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:Python27DataSatellitemanage.py", line 11, in <module>
execute_manager(settings)
File "C:Python27libsite-packagesdjangocoremanagement__init__.py", line 459, in execute_manager
utility.execute()
File "C:Python27libsite-packagesdjangocoremanagement__init__.py", line 382, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:Python27libsite-packagesdjangocoremanagementbase.py", line 196, in run_from_argv
self.execute(*args, **options.__dict__)
File "C:Python27libsite-packagesdjangocoremanagementbase.py", line 232, in execute
output = self.handle(*args, **options)
File "C:Python27libsite-packagesdjangocoremanagementbase.py", line 371, in handle
return self.handle_noargs(**options)
File "C:Python27libsite-packagesdjangocoremanagementcommandssyncdb.py", line 57, in handle_noargs
cursor = connection.cursor()
File "C:Python27libsite-packagesdjangodbbackends__init__.py", line 306, in cursor
cursor = self.make_debug_cursor(self._cursor())
File "C:Python27libsite-packagessqlserver_adobase.py", line 193, in _cursor
self.__connect()
File "C:Python27libsite-packagessqlserver_adobase.py", line 168, in __connect
use_transactions=self.use_transactions,
File "C:Python27libsite-packagessqlserver_adodbapi.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:Python27DataSatellitemanage.py syncdb" execution.
我到处看了看,似乎无法理解和解决问题。我希望有人能帮忙!谢谢
编辑:
我已经创建了数据库。我还使用django-pyodbc连接到了数据库,并成功地从数据库中进行了读写。但是当我使用Apache时,django-pyodbc会引起问题,这就是我决定尝试django-mssql的原因。然而,我不理解它所带来的错误。
我的Django(1.4.2)和Python(2.7)安装在Windows上运行,我使用的是Apache Web服务器。
更新pywin32以构建217或更高版本。我在stackoverflow上发现了另一个问题,也有同样的问题(在另一个主题上):
Python COM服务器抛出';模块';对象没有属性';变体';