Can not connect Django to sql server

9avjhtql  于 2023-05-28  发布在  Go
关注(0)|答案(1)|浏览(91)

I follow the steps from ( Microsoft help to connect SQL server to Django) and then I receive 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'"

  • Python version is 3.10.11
  • Django version is 3.2.19

**steps:

**

Create a Django project

$ django-admin startproject mysite
E

dit setting.py file Go to mysite/mysite/settings.py In DATABASE section, edit accrodingly. Make sure the DATABASE_NAME is exist in your SQL Server instance.

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

Run Django project

Windows

py manage.py runserver

pcww981p

pcww981p1#

Did you install the django-mssql-backend python package? It is required for connecting to MSSQL. You may also need the pyodbc python package.

相关问题