'mssql' (also tried 'sql_server.pyodbc) isn't an available database backend or couldn't be imported

I have been all over the Internet and read, as well as tried, every post and solution I could find. I cannot find a way to connect to SQL Server 2019.

I have installed, uninstalled, reinstalled: mssql-django, django-pyodbc-azure, django-mssql-backend. I’ve tried using one, two and all three at the same time. Nothing works.

I feels like it should be so simple. Setting up and testing a project with a local installation of SQL Server using Windows Default login.

With pyodbc and mssql-django installed (my latest iteration):
settings.py

DATABASES = {
‘default’: {
‘ENGINE’: ‘mssql’,
‘NAME’: ‘mytestdb’,
‘HOST’: ‘thisPC-\MSSQLSERVER01’,
‘PORT’:‘’,
‘OPTIONS’: {
‘driver’: ‘ODBC Driver 17 for SQL Server’,
‘isolation_level’: ‘READ UNCOMMITTED’,
},
}
}…

when I run python manage.py makemigrations TestApp I get a host of errors:
…ModuleNotFoundError: No module named ‘mssql’…
…django.core.exceptions.ImproperlyConfigured: ‘mssql’ isn’t an available database backend or couldn’t be imported…

I don’t know what to try next. I’m at a loss for ideas.

Hey fabi66,

I’m running in the same issue. But for some reasons it works on my laptop, but doesnt work on the windows server.

Did you find the cause of your issue?

I did not find the answer. I continued exploring Django with other database platforms. But ultimately I need something that works seamlessly with SQL Server

Have you tried using mssql-django with settings:

DATABASES = {
    "default": {
        "ENGINE": "mssql",
        "NAME": "mytestdb",
        "HOST": "thisPC-\MSSQLSERVER01"
    }
}

I had this exact same issue and there is NOTHING online that fixed it until I finally, FINALLY, discovered the source of the issue on my own.

I don’t know if this is the same problem everyone with this issue is running into, but I have not seen a SINGLE mention of it in any online discussion, package documentation, or thread ANYWHERE.

The cause of this issue? (for me at least):

At some poin the naming convention of the top-level folder that gets installed by the ‘mssql’ package was changed. Y’know the thing that the entire program depends on to find the package? It was renamed from ‘mssql’ to ‘MsSql’, and yes, it breaks everything and no, nothing else was changed. Even within the package itself it expects ‘mssql’, not ‘MsSql’. and yes, Python treats these as two entirely different things.

If you’re working in a virtual environment (I am, so idk if this is any different if you aren’t), go into the Lib\site-packages subfolder and look for your ‘mssql’ package. If you instead find a package named ‘MsSql’, BINGO. There’s your problem. Change that back to ‘mssql’ and, if everything else is correctly set up, you’re good to go.

I hope this can save someone from the WEEKS of utter pain that this caused me.