'mssql isn't an available database backend or couldn't be imported

I'm following this guide. Mssql-django and I have Django version 3.2.12 I already installed mssql-django 1.1.1 I also have pyodbc 4.0.32

modified my settings.py to have

'ENGINE': 'mssql',

But im still receving this error

django.core.exceptions.ImproperlyConfigured: 'mssql' isn't an available database backend or couldn't be imported. Check the above exception. To use one of the built-in backends, use 'django.db.backends.XXX', where XXX is one 
of:
    'mysql', 'oracle', 'postgresql', 'sqlite3'


Solution 1:[1]

I had a similar problem using Flask. The solution was the following:

  1. Create a file named odbcinst.ini with contents
[FreeTDS]
Driver = /usr/lib/x86_64-linux-gnu/odbc/libtdsodbc.so
  1. The requirements.txt file should have a working version of mssql and pyodbc.

For example :

mssql==1.0.1
pyodbc==4.0.31
  1. And the server configuration has:

    SQLALCHEMY_BINDS = {
    'my_database': "mssql+pyodbc://{}:{}@{}?driver=FreeTDS".format(
        os.getenv("database_user"), 
        os.getenv("database_password"), 
        os.getenv("database_host")
    )
    

    }

  2. And finally the Dockerfile could be something like this:

     FROM python:3.9.8-slim
    
     [...other staff here...]
    
     COPY odbcinst.ini /etc/
    
     [...other staff here...]
    

Hopefully, you will be able to transform the flask idioms into your django application and make it work. This gave me quite a frustration while I was trying to make it work.

Solution 2:[2]

sudo apt-get install unixodbc-dev

Installed unixodbc-dev

pip install pyodbc
pip install mssql-django

but now i have other problem

django.db.utils.Error: ('01000', "[01000] [unixODBC][Driver Manager]Can't open lib 'ODBC Driver 17 for SQL Server' : file not found (0) (SQLDriverConnect)")

and with no idea how to solve it, I already installed driver 17. It just can't find it

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Daedalus
Solution 2 Cristian