【问题标题】:django-pyodbc DatabaseError message is wireddjango-pyodbc DatabaseError 消息已连接
【发布时间】:2014-02-25 08:20:24
【问题描述】:

我在 Django 1.6.1 上使用 django-pyodbc

当我运行manage.py syncdb 时,一切都很好。

我在 Django 中使用 2 个数据库设置从我的旧数据库中读取一些数据,当我从模型名称 T_AllStation 中读取数据时:

all_t_station = T_AllStation.objects.using('SQL_Server').all()

出现错误:

DatabaseError at /company/get_station_info

('42S22', "[42S22] [Microsoft][ODBC SQL Server Driver][SQL Server]\xc1\xd0\xc3\xfb 'id' \xce\xde\xd0\xa7\xa1\xa3 (207) (SQLExecDirectW)")

Request Method:     GET
Request URL:    http://127.0.0.1:8000/company/get_station_info
Django Version:     1.6.1
Exception Type:     DatabaseError
Exception Value:    

('42S22', "[42S22] [Microsoft][ODBC SQL Server Driver][SQL Server]\xc1\xd0\xc3\xfb 'id' \xce\xde\xd0\xa7\xa1\xa3 (207) (SQLExecDirectW)")

Exception Location:     E:\VirtualEnvs\EnvMonitor\lib\site-packages\django_pyodbc\base.py in execute, line 416
Python Executable:  E:\VirtualEnvs\EnvMonitor\Scripts\python.exe
Python Version:     2.7.2

字符串\xc1\xd0\xc3\xfb 'id' \xce\xde\xd0\xa7\xa1\xa3 (207)是什么意思?

【问题讨论】:

    标签: python sql-server django pyodbc django-pyodbc


    【解决方案1】:

    尝试让您的配置文件使用这样的选项,以考虑 Unicode:

    DATABASES = {
        'default': {
            'ENGINE': 'django_pyodbc',
            'NAME': 'db_name',
            'USER': 'db_user',
            'PASSWORD': 'your_password',            
            'HOST': 'database.domain.com,1433',
            'PORT': '1433',
            'OPTIONS': {
                'host_is_server': True,
                'autocommit': True,
                'unicode_results': True,
                'extra_params': 'tds_version=8.0'
            },
        }
    }
    

    (你在 Windows 上,所以你不需要 tds_version,但它不会有什么坏处,所以你的配置可以移植到 Linux。)

    【讨论】:

      猜你喜欢
      • 2021-12-26
      • 1970-01-01
      • 2015-10-26
      • 2021-10-23
      • 2011-05-25
      • 2015-02-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多