0

我是后端的初学者。试图在我的 Windows 机器上测试 Web 服务。

在 linux 服务器上,我有一台具有以下数据库设置的工作机器:

DATABASES = {
'default': {
    'ENGINE': 'django_pyodbc',
    'NAME': 'database_name',
    'USER': 'user@server_name',
    'PASSWORD': 'pass',
    'HOST': 'host',
    'PORT': '1433',
    'OPTIONS': {
        'driver': 'FreeTDS',
    }
},

在向 git 提交任何内容之前,我想在我的 windows pc 上本地运行 web 服务。为此,我正在使用此处提供的 django-pyodbc-azure 1.0.10:

https://github.com/michiya/django-pyodbc-azure/tree/dd87bd3379475ff596210a9243c04c01add0be4d

在我本地的 Windows 电脑上

DATABASES = {
'default': {
    'ENGINE': 'sql_server.pyodbc',
    'NAME': 'database_name',
    'USER': 'user@server_name',
    'PASSWORD': 'pass',
    'HOST': 'server_name.database.windows.net',
    'PORT': '',
    'OPTIONS': {
            'driver': 'SQL Server Native Client 11.0',
            'MARS_Connection': True,
    }
},

我相应地更改了我的设置,但它给出了以下错误:

File "C:\Python27\lib\site-packages\sql_server\pyodbc\base.py", line 396, in execute
raise utils.DatabaseError(*e.args)

DatabaseError: ('42000', '[42000] [Microsoft][SQL Server Native Client 11.0][SQL     Server]Error converting data type nvarchar to int. (8114) (SQLExecDirectW)')

我猜它连接了数据库,但它会产生转换错误。

我正在使用邮递员发布服务

http://127.0.0.1:8000/api/GetFixture 

它引发 500 内部服务器错误。但这项服务在 linux 服务器上运行良好。

4

1 回答 1

0

I use django-pyodbc rather than django-pyodbc-azure, however, it is a fork. I believe you just need to add this to your options on the Linux side:

'OPTIONS': {
    'host_is_server': True,
    'autocommit': True,
    'unicode_results': True,
    'extra_params': 'tds_version=8.0'
},

On the windows machine, just be sure to include:

'host_is_server': True,
'autocommit': True,
'unicode_results': True,

Also note, HOST takes this form:

'HOST': 'database.domain.com,1433',

...where 1433 is the port SQL Server is running on. The autocommit is required for Django 1.6+.

于 2014-05-08T12:36:03.307 回答