No module named sql_server.pyodbc.base
11,681
You have not installed the package with the required DB backend.
Do:
pip install django-pyodbc
pip install django-pyodbc-azure
An example of the database settings from the second link:
DATABASES = {
'default': {
'ENGINE': 'sql_server.pyodbc',
'NAME': 'mydb',
'USER': 'user@myserver',
'PASSWORD': 'password',
'HOST': 'myserver.database.windows.net',
'PORT': '',
'OPTIONS': {
'driver': 'SQL Server Native Client 11.0',
},
},
}
#set this to `False` if you want to turn off pyodbc's connection pooling:
DATABASE_CONNECTION_POOLING = False
Author by
Weihui Guo
For I know the plans I have for you, declares the LORD, plans for welfare and not for evil, to give you a future and a hope. Jeremiah 29:11 ESV
Updated on June 12, 2022Comments
-
Weihui Guo almost 2 years
I wanted to use SQL Server as the backend for Django, but I got this when debugging the web project. 'sql_server.pyodbc' isn't an available database backend. Error was: No module named sql_server.pyodbc.base.
Python Environments (Python 2.7) with Django (1.7), pyodbc(3.0.10), pywin32(218.3). And here is my settings.py:
DATABASES = { 'default': { 'ENGINE': 'sql_server.pyodbc', 'NAME': 'DatabaseName', 'USER': 'user', 'PASSWORD': 'pwd', 'HOST': '127.0.0.1', 'PORT': '', 'OPTIONS': { 'driver': 'SQL Server Native Client 11.0', 'server': 'ServerName', 'MARS_Connection': True, 'dsn': 'MSSQL-PYTHON', }, } }
-
Weihui Guo over 8 yearsI installed django-pyodbc as you suggested, although there is a pyodbc already. It gave me the same error.
-
Ivan over 8 yearsIt seems still like you haven't got the right backend package. Did you try this one ?
-
Weihui Guo over 8 yearsThe link you gave about django-pyodbc-azure 1.8.3.0 actually solved the problem. Somehow when I installed it, it also updated my Django to 1.8.4. So I guess matching the version really matters. Please update your answer so I can accept it. Thank you very much!
-
Weihui Guo over 8 yearsIt seems that django-pyodbc-azure (1.8.3.0) only provides sql_server.pyodbc.base. If I remove pyodbc and leave django-pyodbc-azure alone, it gives me different error. I need both pyodbc (3.0.10) and django-pyodbc-azure (1.8.3.0)
-
joaorodr84 over 7 yearsIf you don't want to update Django 1.9 to 1.10, do not install the latest version of django-pyodbc-azure. Here are the versions I installed: pyodbc==3.0.10, django-pyodbc==1.0.1, django-pyodbc-azure==1.9.6 ... Cheers!
-
Dinei about 7 yearsFuture readers: under Linux I kept getting errors like
error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
and had toapt-get install unixodbc-dev
beforepip install django-pyodbc
to work.