Skip to content

Invalid collation 'SQL_Latin1_General_CP1_CS_AI' when database collation is 'SQL_Latin1_General_CP1_CI_AI' #420

@daarsan

Description

@daarsan

When our database is case and accent insensitive, search functionality does not work.

Software versions

  • Django: 5.0
  • mssql-django: 1.5
  • python: 3.12
  • SQL Server: 15.0.4390
  • OS: Windows

The root case is the function sqlserver_replace in functions.py. In that method, there is a replace where that changes CI by CS. If the default collation is SQL_Latin1_General_CP1_CI_AI, the result is SQL_Latin1_General_CP1_CS_AI which does not exist.
The exception is as follows:

django.db.utils.ProgrammingError: ('42000', "[42000] [Microsoft][ODBC Driver 18 for SQL Server][SQL Server]Invalid collation 'SQL_Latin1_General_CP1_CS_AI'. (448) (SQLExecDirectW); [42000] [Microsoft][ODBC Driver 18 for SQL Server][SQL Server]Statement(s) could not be prepared. (8180)")

My suggestion is to replace the current line:
current_collation = default_collation.replace('_CI', '_CS')
by
current_collation = default_collation.replace('_CI', '_CS') if default_collation.endswith('_AS') else default_collation

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions