sql-serverdjangopython-3.xdjango-pyodbc

django: The database driver doesn't support modern datatime types


I am trying the connect the MSSQL server and pull the data from the SQL server.

I landed on below error.

"django.core.exceptions.ImproperlyConfigured: The database driver doesn't support modern datatime types."

Version: Django: 2.2 Python: 3.7 django-pyodbc-azure-2.1.0.0 pyodbc-4.0.26

 DATABASES = {
     'default': {
         'ENGINE': 'sql_server.pyodbc',
         'HOST': 'server\\DB',
         'NAME': 'Archive',
         'USER': 'Admin',
         'PASSWORD': '*****',
         'PORT': '49422',

         'OPTIONS': {
             'driver': 'SQL Server',
             'dsn': 'Django',
             'extra_params': "Persist Security Info=False;server=server\\DB",
         },
     }
 }

Solution

  • The "SQL Server" ODBC driver that ships with windows is unaware of SQL Server data types introduced after SQL Server 2000 (e.g. date, time, datetime2, datetimeoffset). It is intended only for legacy applications and shouldn't be used for new development.

    Instead, download and install the separately distributed ODBC driver. In addition to supporting newer data types, the newer drivers support TLS protocol enhancements and encryption features. The current ODBC driver as of this writing is the ODBC Driver 17 for SQL Server.