{"id":16417454,"url":"https://github.com/microsoft/mssql-django","last_synced_at":"2026-04-24T11:03:56.938Z","repository":{"id":37073319,"uuid":"305859005","full_name":"microsoft/mssql-django","owner":"microsoft","description":"The Microsoft Django backend for SQL Server provides a connectivity layer for Django on SQL Server or Azure SQL DB.","archived":false,"fork":false,"pushed_at":"2024-09-26T18:54:36.000Z","size":1221,"stargazers_count":357,"open_issues_count":66,"forks_count":120,"subscribers_count":24,"default_branch":"dev","last_synced_at":"2025-02-07T17:16:54.708Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/microsoft.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.txt","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":"SUPPORT.md","governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-10-20T23:43:05.000Z","updated_at":"2025-02-06T18:26:48.000Z","dependencies_parsed_at":"2022-07-21T21:47:43.017Z","dependency_job_id":"e3a5c328-709c-4846-b289-0828919e1349","html_url":"https://github.com/microsoft/mssql-django","commit_stats":{"total_commits":622,"total_committers":53,"mean_commits":"11.735849056603774","dds":0.635048231511254,"last_synced_commit":"d07417217065ef2539c8b2a8afb81f762086e09c"},"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/microsoft%2Fmssql-django","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/microsoft%2Fmssql-django/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/microsoft%2Fmssql-django/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/microsoft%2Fmssql-django/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/microsoft","download_url":"https://codeload.github.com/microsoft/mssql-django/tar.gz/refs/heads/dev","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238394323,"owners_count":19464583,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-11T07:11:31.166Z","updated_at":"2026-04-24T11:03:56.929Z","avatar_url":"https://github.com/microsoft.png","language":"Python","funding_links":[],"categories":["Python"],"sub_categories":[],"readme":"# Django Backend for Microsoft SQL\n\nmssql-django is the official Microsoft‑supported Django database backend for SQL Server, Azure SQL and SQL Database in Microsoft Fabric. \n\nIt provides a reliable, enterprise‑grade database connectivity option for the Django web framework, enabling Python developers to build and run production‑ready applications on Microsoft’s data platform.\n\nThis project is the continuation and evolution of earlier community efforts, and it builds on the strong foundation established by django-mssql-backend and its predecessors. mssql-django focuses on long‑term stability, performance, security, and compatibility with both Django and SQL Server.\n\n## Supportability\n\n| Component | Supported Versions |\n|---|---|\n| Django | 3.2, 4.0, 4.1, 4.2, 5.0, 5.1, 5.2, 6.0 |\n| Python | 3.8 – 3.14 (Django 6.0 requires 3.12+) |\n| SQL Server | 2016, 2017, 2019, 2022, 2025 |\n| Azure SQL | Database, Managed Instance, SQL Database in Microsoft Fabric |\n| ODBC Driver | Microsoft ODBC Driver 17 or 18 for SQL Server |\n| FreeTDS | Supported via FreeTDS ODBC driver |\n\n## Quick Start\n\n1. Install mssql-django (pulls in Django, pyodbc, and pytz automatically):\n\n       pip install mssql-django\n\n2. Configure your `settings.py`:\n\n```python\nDATABASES = {\n    'default': {\n        'ENGINE': 'mssql',\n        'NAME': 'mydb',\n        'USER': 'user@myserver',\n        'PASSWORD': 'password',\n        'HOST': 'myserver.database.windows.net',\n        'PORT': '',\n        'OPTIONS': {\n            'driver': 'ODBC Driver 18 for SQL Server',\n        },\n    },\n}\n\n# set this to False if you want to turn off pyodbc's connection pooling\nDATABASE_CONNECTION_POOLING = False\n```\n\n## Configuration Reference\n\n### Standard Django Settings\n\n| Setting | Type | Description |\n|---|---|---|\n| `ENGINE` | String | Must be `\"mssql\"` |\n| `NAME` | String | Database name. Required. |\n| `HOST` | String | SQL Server instance in `\"server\\instance\"` format |\n| `PORT` | String | Server instance port. Empty string means default port. |\n| `USER` | String | Database user name. If not given, MS Integrated Security is used. |\n| `PASSWORD` | String | Database user password |\n| `TOKEN` | String | Access token for Azure AD auth (e.g. via `azure.identity`) |\n| `AUTOCOMMIT` | Boolean | Set to `False` to disable Django's transaction management |\n| `Trusted_Connection` | String | Default `\"yes\"`. Set to `\"no\"` if required. |\n\n### TEST Settings\n\n| Setting | Type | Description |\n|---|---|---|\n| `NAME` | String | Test database name. Default: `\"test_\" + NAME` |\n| `COLLATION` | String | Collation for test database. Default: instance default. |\n| `DEPENDENCIES` | String | Creation-order dependencies of the database |\n| `MIRROR` | String | Alias of database to mirror during testing |\n\n### OPTIONS\n\n| Option | Type | Default | Description |\n|---|---|---|---|\n| `driver` | String | `\"ODBC Driver 18 for SQL Server\"` | ODBC driver to use. Auto-falls back to Driver 17 if 18 is not installed. |\n| `isolation_level` | String | `None` | [Transaction isolation level](https://docs.microsoft.com/en-us/sql/t-sql/statements/set-transaction-isolation-level-transact-sql): `READ UNCOMMITTED`, `READ COMMITTED`, `REPEATABLE READ`, `SNAPSHOT`, or `SERIALIZABLE` |\n| `dsn` | String | — | Named DSN, can be used instead of `HOST` |\n| `host_is_server` | Boolean | `False` | Set to `True` to use `HOST`/`PORT` directly with FreeTDS instead of a `freetds.conf` dataserver name. [Details](https://www.freetds.org/userguide/dsnless.html) |\n| `unicode_results` | Boolean | `False` | Activate pyodbc's unicode\\_results feature |\n| `extra_params` | String | — | Additional ODBC params (`\"param=value;param=value\"`). Use for [Azure AD Authentication](https://github.com/microsoft/mssql-django/wiki/Azure-AD-Authentication). |\n| `collation` | String | `None` | Collation for text field lookups (e.g. `\"Chinese_PRC_CI_AS\"`) |\n| `connection_timeout` | Integer | `0` | Connection timeout in seconds (`0` = disabled) |\n| `connection_retries` | Integer | `5` | Number of connection retry attempts |\n| `connection_retry_backoff_time` | Integer | `5` | Back-off time in seconds between retries |\n| `query_timeout` | Integer | `0` | Query timeout in seconds (`0` = disabled) |\n| `setencoding` / `setdecoding` | List | — | pyodbc [encoding](https://github.com/mkleehammer/pyodbc/wiki/Connection#setencoding) / [decoding](https://github.com/mkleehammer/pyodbc/wiki/Connection#setdecoding) config |\n| `return_rows_bulk_insert` | Boolean | `False` | Allow returning rows from bulk insert. Must be `False` if tables have triggers. |\n\n### Backend-Specific Settings\n\n| Setting | Type | Default | Description |\n|---|---|---|---|\n| `DATABASE_CONNECTION_POOLING` | Boolean | `True` | Set to `False` to disable pyodbc's connection pooling |\n\n## Known Limitations\n\nThe following limitations apply when using SQL Server with Django:\n\n- Altering a model field from or to AutoField at migration\n- Floating point arithmetic in some annotate functions\n- Annotate/exists function in `order_by`\n- Righthand power and arithmetic with datetimes\n- Timezones and timedeltas not fully supported\n- Rename field/model with foreign key constraint\n- Database level constraints and filtered indexes\n- Date extract function\n- Bulk insert with triggers and returning rows\n\n### Version-Specific Notes\n\n| Version | Notes |\n|---|---|\n| Django 5.1 | Minor limitations with composite primary key inspection via `inspectdb` |\n| Django 5.2 | Tuple lookups require Django 5.2.4+ for full support. Some JSONField bulk/CASE WHEN update edge cases. See [test exclusions](https://github.com/microsoft/mssql-django/blob/dev/testapp/settings.py) for details. |\n| Django 6.0 | Requires Python 3.12+. All 5.2 limitations apply. Backend handles all 6.0 API changes transparently. |\n\nJSONField lookups have additional limitations — see the [JSONField wiki page](https://github.com/microsoft/mssql-django/wiki/JSONField).\n\n## Helpful Links\n\n| Resource | Link |\n|---|---|\n| Wiki \u0026 Guides | [mssql-django Wiki](https://github.com/microsoft/mssql-django/wiki) |\n| Contributing | [Contributing Guide](https://github.com/microsoft/mssql-django/blob/dev/CONTRIBUTING.md) |\n| Code of Conduct | [Microsoft Open Source Code of Conduct](https://github.com/microsoft/mssql-django/blob/dev/CODE_OF_CONDUCT.md) |\n\n## Still have questions?\n\nCheck the [FAQ](https://github.com/microsoft/mssql-django/wiki/Frequently-Asked-Questions) or [open an issue](https://github.com/microsoft/mssql-django/issues/new) on GitHub.\n\n## Contributing\n\nWe welcome contributions and suggestions! See [CONTRIBUTING.md](https://github.com/microsoft/mssql-django/blob/dev/CONTRIBUTING.md) for details.\n\nAll contributors are listed on GitHub: [Contributor Insights](https://github.com/microsoft/mssql-django/graphs/contributors)\n\nMost contributions require a Contributor License Agreement (CLA). For details, visit https://cla.opensource.microsoft.com. A CLA bot will guide you when you submit a pull request.\n\nThis project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).\n\n## Security\n\nFor security reporting instructions please refer to [`SECURITY.md`](https://github.com/microsoft/mssql-django/blob/dev/SECURITY.md).\n\n## Trademarks\n\nThis project may contain trademarks or logos for projects, products, or services. Authorized use of Microsoft\ntrademarks or logos is subject to and must follow\n[Microsoft's Trademark \u0026 Brand Guidelines](https://www.microsoft.com/en-us/legal/intellectualproperty/trademarks/usage/general).\nUse of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship.\nAny use of third-party trademarks or logos are subject to those third-party's policies.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmicrosoft%2Fmssql-django","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmicrosoft%2Fmssql-django","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmicrosoft%2Fmssql-django/lists"}