No module named sql_server.pyodbc.base

匿名 (未验证) 提交于 2019-12-03 00:52:01

问题:

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',         },     } } 

回答1:

You have not installed the package with the required DB backend.

Do:

pip install django-pyodbc pip install django-pyodbc-azure 

See this doc and this one.

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 


回答2:

Take a look at this link:

DATABASES = {     'default': {         'NAME': 'my_database',         'ENGINE': 'sqlserver_ado',         'HOST': 'dbserver\\ss2008',         'USER': '',         'PASSWORD': '',     } } 

Supposedly you can use SQL Server with Django MSSQL (link above). you might want to check the [Django documentation] to see what other database support django supports "natively". (https://docs.djangoproject.com/en/1.8/ref/settings/#databases)



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!