Package: azure-msi-mssql-django
SQL Server backend for DjangoWelcome to the azure-msi-mssql-django 3rd party backend project!azure-msi-mssql-djangois a fork ofmssql-django. This project provides an enterprise database connectivity option for the Django Web Framework, with support for Microsoft SQL Server and Azure SQL Database.We'd like to give thanks to the community that made this project possible, with particular recognition of the contributors: OskarPersson, michiya, dlo and the original Google Code django-pyodbc team. Moving forward we encourage partipation in this project from both old and new contributors!We hope you enjoy using the azure-msi-mssql-django 3rd party backend.FeaturesSupports Django 3.2 and 4.0Tested on Microsoft SQL Server 2016, 2017, 2019Passes most of the tests of the Django test suiteCompatible withMicosoft ODBC Driver for SQL Server,SQL Server Native Client,
andFreeTDSODBC driversDependenciespyodbc 3.0 or newerInstallationInstall pyodbc 3.0 (or newer) and DjangoInstall azure-msi-mssql-django:pip install azure-msi-mssql-djangoSet theENGINEsetting in thesettings.pyfile used by
your Django application or project to'mssql':'ENGINE': 'mssql'ConfigurationStandard Django settingsThe following entries in a database-level settings dictionary
in DATABASES control the behavior of the backend:ENGINEString. It must be"mssql".NAMEString. Database name. Required.HOSTString. SQL Server instance in"server\instance"format.PORTString. Server instance port.
An empty string means the default port.USERString. Database user name in"user"format.
If not given then MS Integrated Security will be used.PASSWORDString. Database user password.TOKENString. Access token fetched as a user or service principal which
has access to the database. E.g. when usingazure.identity, the
result ofDefaultAzureCredential().get_token('https://database.windows.net/.default')can be passed.AUTOCOMMITBoolean. Set this toFalseif you want to disable
Django's transaction management and implement your own.Trusted_ConnectionString. Default is"yes". Can be set to"no"if required.and the following entries are also available in theTESTdictionary
for any given database-level settings dictionary:NAMEString. The name of database to use when running the test suite.
If the default value (None) is used, the test database will use
the name"test_" + NAME.COLLATIONString. The collation order to use when creating the test database.
If the default value (None) is used, the test database is assigned
the default collation of the instance of SQL Server.DEPENDENCIESString. The creation-order dependencies of the database.
See the official Django documentation for more details.MIRRORString. The alias of the database that this database should
mirror during testing. Default value isNone.
See the official Django documentation for more details.OPTIONSDictionary. Current available keys are:driverString. ODBC Driver to use ("ODBC Driver 17 for SQL Server","SQL Server Native Client 11.0","FreeTDS"etc).
Default is"ODBC Driver 17 for SQL Server".isolation_levelString. Setstransaction isolation levelfor each database session. Valid values for this entry areREAD UNCOMMITTED,READ COMMITTED,REPEATABLE READ,SNAPSHOT, andSERIALIZABLE. Default isNonewhich means
no isolation level is set to a database session and SQL Server default
will be used.dsnString. A named DSN can be used instead ofHOST.host_is_serverBoolean. Only relevant if using the FreeTDS ODBC driver under
Unix/Linux.By default, when using the FreeTDS ODBC driver the value specified in
theHOSTsetting is used in aSERVERNAMEODBC connection
string component instead of being used in aSERVERcomponent;
this means that this value should be the name of adataserverdefinition present in thefreetds.confFreeTDS configuration file
instead of a hostname or an IP address.But if this option is present and its value isTrue, this
special behavior is turned off. Instead, connections to the database
server will be established usingHOSTandPORToptions, without
requiringfreetds.confto be configured.Seehttps://www.freetds.org/userguide/dsnless.htmlfor more information.unicode_resultsBoolean. If it is set toTrue, pyodbc'sunicode_resultsfeature
is activated and strings returned from pyodbc are always Unicode.
Default value isFalse.extra_paramsString. Additional parameters for the ODBC connection. The format is"param=value;param=value",Azure AD Authentication(Service Principal, Interactive, Msi) can be added to this field.collationString. Name of the collation to use when performing text field
lookups against the database. Default isNone; this means no
collation specifier is added to your lookup SQL (the default
collation of your database will be used). For Chinese language you
can set it to"Chinese_PRC_CI_AS".connection_timeoutInteger. Sets the timeout in seconds for the database connection process.
Default value is0which disables the timeout.connection_retriesInteger. Sets the times to retry the database connection process.
Default value is5.connection_retry_backoff_timeInteger. Sets the back off time in seconds for reries of
the database connection process. Default value is5.query_timeoutInteger. Sets the timeout in seconds for the database query.
Default value is0which disables the timeout.setencodingandsetdecoding# Example"OPTIONS":{"setdecoding":[{"sqltype":pyodbc.SQL_CHAR,"encoding":'utf-8'},{"sqltype":pyodbc.SQL_WCHAR,"encoding":'utf-8'}],"setencoding":[{"encoding":"utf-8"}],...},return_rows_bulk_insertBoolean. Sets if backend can return rows from bulk insert.
Default value is False which doesn't allows for the backend to
return rows from bulk insert. Must be set to False if database
has tables with triggers to prevent errors when inserting.# Examples"OPTIONS":{# This database doesn't have any triggers so can use return# rows from bulk insert feature"return_rows_bulk_insert":True}"OPTIONS":{# This database has triggers so leave return_rows_bulk_insert as blank (False)# to prevent errors related to inserting and returning rows from bulk insert}Backend-specific settingsThe following project-level settings also control the behavior of the backend:DATABASE_CONNECTION_POOLINGBoolean. If it is set toFalse, pyodbc's connection pooling feature
won't be activated.ExampleHere is an example of the database settings forazure token:DATABASES = {
    'default': {
        'ENGINE': 'sql_server.pyodbc',
        'NAME': 'mydb',
        'HOST': 'myserver.database.windows.net',
        'PORT': '',
        'IS_AZURE_BASED_TOKEN': True,
        'OPTIONS': {
            'driver': 'ODBC Driver 17 for SQL Server',
        },
    },
}If you are using alocal SQL server, use the below configuration.DATABASES = {
    'default': {
        'ENGINE': 'sql_server.pyodbc',
        'NAME': 'mydb',
        'USER': 'user@myserver',
        'PASSWORD': 'password',
        'HOST': 'myserver.database.windows.net',
        'PORT': '',
        'IS_AZURE_BASED_TOKEN': False,

        'OPTIONS': {
            'driver': 'ODBC Driver 17 for SQL Server',
        },
    },
}

# set this to False if you want to turn off pyodbc's connection pooling
DATABASE_CONNECTION_POOLING = FalseLimitationsThe following features are currently not fully supported:Altering a model field from or to AutoField at migrationDjango annotate functions have floating point arithmetic problems in some casesAnnotate function with existsExists function in order_byRighthand power and arithmetic with datatimesTimezones, timedeltas not fully supportedRename field/model with foreign key constraintDatabase level constraintsMath degrees power or radiansBit-shift operatorsFiltered indexDate extract functionBulk insert into a table with a trigger and returning the rows insertedJSONField lookups have limitations, more detailshere.ContributingMore details on contributing can be foundhere.This project welcomes contributions and suggestions.  Most contributions require you to agree to a
Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us
the rights to use your contribution. For details, visithttps://cla.opensource.microsoft.com.When you submit a pull request, a CLA bot will automatically determine whether you need to provide
a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions
provided by the bot. You will only need to do this once across all repos using our CLA.This project has adopted theMicrosoft Open Source Code of Conduct.
For more information see theCode of Conduct FAQor
contactopencode@microsoft.comwith any additional questions or comments.Security Reporting InstructionsFor security reporting instructions please refer to theSECURITY.mdfile in this repository.TrademarksThis project may contain trademarks or logos for projects, products, or services. Authorized use of Microsoft
trademarks or logos is subject to and must followMicrosoft's Trademark & Brand Guidelines.
Use of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship.
Any use of third-party trademarks or logos are subject to those third-party's policies.