pythonsql-serverdjangodatabasedjango-mssql-backend

Error while trying to connect Django to SQL Server using django-mssql-backend


Windows 10   
SQL Server 2019  
Python 3.9.1  
Django 3.2.5  

pip freeze: 
  asgiref==3.4.1  
  Django==3.2.5    
  django-mssql-backend==2.8.1  
  djangorestframework==3.12.4  
  pyodbc==4.0.30  
  pytz==2021.1  
  sqlparse==0.4.1 

DATABASES = {
    'default': {
        'ENGINE': 'sql_server.pyodbc',
        'NAME': 'dbForDjango',
        'USER': 'sa',
        'PASSWORD': 'sdf874sd21',
        'HOST': 'DESKTOP-AR76KF2\SQL_SERVER',
        'PORT': '',

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

I can run the server without any problem also py manage.py shell is working but Django can't communicate with the database at all.
The command "py manage.py dbshell" occurs this error:

enter image description here

Please ignore the directory name "playingWithFastAPI", am using Django not FastAPI :)

py manage.py migrate occurs that error:

enter image description here


Solution

  • The dbshell error is a known issue (see https://github.com/ESSolutions/django-mssql-backend/issues/100), as django-mssql-backend is not compatible with Django 3.1+