Connecting Django with MSSQL server

后端 未结 3 450
心在旅途
心在旅途 2021-01-21 12:35

I\'m trying to connect my Django app to SQL Server 2016. I\'ve tried using django-pyodbc but it doesn\'t support Django 1.11. Instead I installed django-mssql 1.8. When I try to

3条回答
  •  無奈伤痛
    2021-01-21 13:08

    You can use django-pyodbc-azure because it has support up to current versions of django 2.0. After installation you need to edit in your settings file like below:

    DATABASES = {
        'default': {
            'ENGINE': 'sql_server.pyodbc',
            'NAME': DB_NAME,
            'USER': USER,
            'PASSWORD': PASSWORD,
            'HOST': HOST,
            'PORT': PORT,
            'OPTIONS': {
                'driver': 'ODBC Driver 13 for SQL Server',
                'unicode_results': True,
    
            },
        }
    }
    

    If you install TDS library as driver then your driver will be 'driver':'Free TDS' Here 13 is the default version. If your installed version is different from that then use that version number instead of 13

提交回复
热议问题