开发者

Django and SQL Server - Error when charfield > 10 chars

I'm using Django 1.2.3 and django-pyodbc.

I am receiving an error when adding a user with length > 10chars:

The data types nvarchar and ntext ar开发者_如何学Pythone incompatible in the equal to operator


Whenever I add a user with username of 10 characters or below it works fine, same error for emails.

Any idea folks?


The user table:

CREATE TABLE [auth_user] (
    [id] int IDENTITY (1, 1) NOT NULL PRIMARY KEY,
    [username] nvarchar(30) NOT NULL UNIQUE,
    [first_name] nvarchar(30) NOT NULL,
    [last_name] nvarchar(30) NOT NULL,
    [email] nvarchar(75) NOT NULL,
    [password] nvarchar(128) NOT NULL,
    [is_staff] bit NOT NULL,
    [is_active] bit NOT NULL,
    [is_superuser] bit NOT NULL,
    [last_login] datetime NOT NULL,
    [date_joined] datetime NOT NULL
)


I had a similar problem with SQL Server 2008 and the SQL Native Client odbc driver. Upgrading to SQL Server 2008 R2 fixed the problem. It seemed to be caused by an issue with the results from the SQLGetTypeInfo() odbc call for the WVARCHAR type including some date/time types too.


Try python manage.py sqlall <appname> to see what the definition of CREATE TABLE for your table.


Under Linux, I fixed it by setting the TDS Version to 7.2:

    'OPTIONS': {
        'driver': '/usr/lib/libtdsodbc.so',
        'host_is_server': True,
        'extra_params': 'TDS_Version=7.2',
    }

See the next link for a table of TDS Versions: Choosing a TDS protocol version

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜