How does Django connect to Microsoft SQL Server?

Mahabubur Rahman

 By default Django support only Postgres and SQLite. But you can connect SQL database. You need to install a package for SQL database connectivity.

Using mssql-django 1.0 package you can connect SQL database.


  1. Install  Django

  2. Install mssql-django:

    pip install mssql-django
  3. Set the ENGINE setting in the file used by your Django application or project to 'mssql':

    'ENGINE': 'mssql'

Standard Django Settings :

The following entries in database-level settings control the behavior of the backend.

    String. It must be "mssql".

  • NAME

    String. Database name. Required.

  • HOST

    String. SQL Server instance in "server\instance" format.

  • PORT

    String. Server instance port. An empty string means the default port.

  • USER

    String. Database user name.


    String. Database user password.

  • driver

    String. 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".

Configuration Example :

        'default': {
            'ENGINE': 'mssql',
            'NAME': 'mydb',
            'USER': 'user@myserver',
            'PASSWORD': 'password',
            'HOST': '',
            'PORT': '',

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

Post a Comment

Post a Comment (0)