Using Sql Server with Django 2.0

2020-07-09 03:05发布

I would like to use Django 2.0 with legacy MS SQL Server database.

Latest information regarding usage Django with MS SQL Server i could find is Using Sql Server with Django in production/These days and it is about Django 1.11 Most supported seems django-pyodbc-azure but it's not supporting Django 2.0 yet: django-pyodbc-azure issue #124

Is there any alternative?

2条回答
一夜七次
2楼-- · 2020-07-09 03:47

Found the solution and post it if anyone facing same problem.

I used django-pyodbc-azure 2.0.4.1 in my Django 2.0.4

The settings that worked for me:

DATABASES = {
    'default': {
        'ENGINE': 'sql_server.pyodbc',
        'NAME': 'dbName',
        'USER': 'yourUserName',
        'PASSWORD': 'yourPassword',
        'HOST': '(local)',
        'PORT': '',
        'OPTIONS': {
            'driver': 'ODBC Driver 11 for SQL Server',
        },
    }
}
查看更多
叛逆
3楼-- · 2020-07-09 03:48

I was facing same error of ODBC Driver Manager

django.db.utils.InterfaceError: ('IM002', '[IM002] [Microsoft][ODBC Driver Manag er] Data source name not found and no default driver specified (0) (SQLDriverCon nect)')

Solution: When i added below code in database connection, then my error fixed.
'OPTIONS': { 'host_is_server': True, 'driver': 'ODBC Driver 11 for SQL Server', }

查看更多
登录 后发表回答