Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
daarsan opened this issue Nov 20, 2024 · 0 comments

Comments

@daarsan
Copy link

daarsan commented Nov 20, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant