
Start by installing the mssql-django database adapter with Python's package manager, for example python -m pip install mssql-django. We added MS SQL through Django's
multi-DB-functionality,
so that the application can choose which database to connect to. Configure
DATABASES in settings.py, and use these environment variables for the connection:
Additional configurable options for the adapter are described in the official documentation: https://github.com/microsoft/mssql-django#options
To test the connection before deployment, you can start a local database server.
Microsoft offers a Docker image,
and we have made one Docker Compose file
which makes the setup easier. Change the image tag 2019-latest if you want to use one
different database version.
In addition to the database server, you must install Microsoft's ODBC driver and the the necessary system packages locally. The same dependencies must be included the container if you build a Docker image of the Django application.
For more information, see this the installation guide.
Test the connection locally before proceeding to deployment.
Getting started with MS SQL in Django is easy, but the technology has others
properties than PostgreSQL. Check in particular whether the solution uses
PostgreSQL-specific field types, such as ArrayField, and whether there is an equivalent
type in MS SQL before changing the database.
The database adapter also has some limitations, among other things related to date fields with time zone. We recommend reading through the list to see if there are any deal breakers for your particular application. In our case, we had to make manual changes to some migration files so that these could be executed on the MS SQL server without problems.
Finally, a reminder if you write raw SQL queries; The MS SQL syntax is different e.g. PostgreSQL's. We assume that most people who use Django relate to the ORM to a large extent, but if you have areas that do not, you will have to rewrite the queries.
From MVP prototypes to scalable platforms, our full-stack dev team turns your roadmap into rock-solid code. Get to market faster without sacrificing quality.
Get started