1
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

2 Answers 2

2

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+

Sign up to request clarification or add additional context in comments.

2 Comments

thank you for this info, by following the link in the issue I found this: "DatabaseClient.runshell() now requires an additional parameters argument as a list of extra arguments to pass on to the command-line client.", is this the solution for that problem ? how can I implement it ?
That's a source code change. So if you really need the dbshell command, you can either roll back to Django 3.0, or wait for a patched version of django-mssql-backend or mssql-django. I should make it clear - you're connecting to the database just fine. It's only dbshell that's buggy. From your second image, it looks like you have issues with your migrations being out of sync with the db.
0

so with Django version more than 3.2, you must use mssql-django. https://learn.microsoft.com/en-us/samples/azure-samples/mssql-django-samples/mssql-django-samples/ and goodluck for you

py -m pip install django mssql-django

# settings.py
DATABASES = {
    "default": {
        "ENGINE": "mssql",
        "NAME": "DATABASE_NAME",
        "USER": "USER_NAME",
        "PASSWORD": "PASSWORD",
        "HOST": "HOST_ADDRESS",
        "PORT": "1433",
        "OPTIONS": {"driver": "ODBC Driver 17 for SQL Server", 
        },
    },
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.