标签: django-pyodbc-azure

Django python 'sql_server.pyodbc' 不是可用的数据库后端

我正在尝试将 Django 应用程序连接到 apache 服务器上的 microsoft sql 数据库,但收到以下错误消息:

django.core.exceptions.ImproperlyConfigured: 'sql_server.pyodbc' isn't an available database backend.
Try using 'django.db.backends.XXX', where XXX is one of:
'mysql', 'oracle', 'postgresql', 'sqlite3'
Run Code Online (Sandbox Code Playgroud)

我已经安装了 django-pyodbc-azure 并且它显示为(pip freeze list)的一部分:

Django==2.1
django-pyodbc==1.1.3
django-pyodbc-azure==2.1.0.0
pyodbc==4.0.25
Run Code Online (Sandbox Code Playgroud)

这是settings.py数据库配置:

'default': {
    'ENGINE': 'sql_server.pyodbc',
    'NAME': 'name',
    'USER': 'user',
    'PASSWORD': 'password',
    'HOST': 'host',
    'PORT': '',

    'OPTIONS': {
        'driver': 'ODBC Driver 17 for SQL Server',
    },

},
Run Code Online (Sandbox Code Playgroud)

在 site-packages 文件夹内,它不显示实际的 django-pyodbc-azure 文件夹,但是当我运行命令(pip show django-pyodbc-azure)时,它显示包位置(/usr/local/lib/python3.1)。 5/dist-packages)表示安装成功。

所以我不太确定问题是什么。

python sql-server django django-pyodbc-azure

12
推荐指数
2
解决办法
3万
查看次数

使用先前工作配置的django-pyodbc-azure回滚错误 - 第389行

我一直在Linux上使用django-pyodbc-azure一段时间,还有pydobc,FreeTDS和unixODBC将Django连接到SQL Server 2014.我遇到了这个问题,我的应用程序工作正常,调试有问题它.为了重现这个问题,我开始使用全新的Django应用程序来保持简单.这是我的virtualenv:

(azuretest)[vagrant@vagrant azuretest]$ pip freeze
Django==1.8.6
django-pyodbc-azure==1.8.3.0
pyodbc==3.0.10
Run Code Online (Sandbox Code Playgroud)

这是我连接到SQL Server的数据库配置:

DATABASES = {
    'default': {
        'ENGINE': 'sql_server.pyodbc',
        'HOST': 'myserver.com',
        'PORT': '1433',
        'NAME': 'my_db',
        'USER': 'my_db_user',
        'PASSWORD': 'mypw',
        'AUTOCOMMIT': True,
        'OPTIONS': {
            'driver': 'FreeTDS',
            'autocommit': True,
            'unicode_results': True,
            'host_is_server': True,
            'extra_params': 'tds_version=7.2',
        },
    },
}
Run Code Online (Sandbox Code Playgroud)

我创建了一个简单的models.py:

class TestTemp(models.Model):
    tempdate = models.DateField()
Run Code Online (Sandbox Code Playgroud)

这个设置在一个相当复杂的Django项目中运行良好,该项目仍可以SELECT到同一个数据库.但是,每当我尝试进行UPDATE或迁移时,我都会收到此错误:

(azuretest)[vagrant@vagrant azuretest]$ ./manage.py migrate home
Operations to perform:
  Apply all migrations: home
Running migrations:
  Rendering model states... DONE
  Applying home.0001_initial...Traceback (most recent call last):
  File "/home/vagrant/.virtualenvs/azuretest/lib/python3.4/site-packages/sql_server/pyodbc/base.py", line …
Run Code Online (Sandbox Code Playgroud)

python sql-server django pyodbc django-pyodbc-azure

8
推荐指数
1
解决办法
540
查看次数

如何在Sql Server中使用Django

我通常在Django中使用Postgres来满足我的数据库需求,但是最近我在一家在Windows环境中使用MSSQL的公司开始工作。长话短说,我不得不重写settings.py中的数据库属性。不幸的是,我不知道如何使用Pyodbc连接到SQL Server,并且它们正在运行Python 3.x,所以我不能使用Django-Pyodbc。尝试运行它时,我得到一个:“找不到数据源名称,并且未指定默认驱动程序(0)(SQLDriverConnect)')”

这是我目前的数据库配置。我可能做错了事,但是很难找到资源,因为大多数Django + Sql Server结果要么使用FreeTDS要么使用Django-Pyodbc(都不是选项)。

'default': {
    'ENGINE': 'sql_server.pyodbc',
    'NAME': 'db_name_on_server',
    'USER': 'my_acct',
    'PASSWORD': 'nope',
    'HOST': 'x.x.x.x',
    'PORT': '1433',
    'OPTIONS': {  # Options are not edited
        'driver': 'SQL Server',  # What it displays as on odbc admin   
        'dsn': 'System DSN',  # What it displays as on odbc admin
        'use_legacy_datetime': False
    }
Run Code Online (Sandbox Code Playgroud)

django pyodbc django-pyodbc-azure

5
推荐指数
2
解决办法
8590
查看次数

尝试使用django-pyodbc-azure连接到MSSQL会导致找不到文件错误

我认为我的问题或多或少是试图从在Linux上运行的django查询SQL Server的重复- 无法打开lib'/ path/to/libtdsodbc.so',但答案完全没有用.

我使用以下东西:

  1. Ubuntu 15.04
  2. Python3
  3. Django 1.9 (通过pip3安装)
  4. freetds-dev 0.91-6build1 通过apt-get安装
  5. django-pyodbc-azure/ django-pyodbc通过pip3安装
  6. MSSQL 2012

尝试连接时,执行python3 manage.py inspectdb以下操作:

Traceback (most recent call last):
  File "/usr/local/lib/python3.4/dist-packages/django/db/backends/base/base.py", line 199, in ensure_connection
    self.connect()
  File "/usr/local/lib/python3.4/dist-packages/django/db/backends/base/base.py", line 171, in connect
    self.connection = self.get_new_connection(conn_params)
  File "/usr/local/lib/python3.4/dist-packages/sql_server/pyodbc/base.py", line 302, in get_new_connection
    timeout=timeout)
pyodbc.Error: ('01000', "[01000] [unixODBC][Driver Manager]Can't open lib 'FreeTDS' : file not found (0) (SQLDriverConnect)")

The above exception was the direct cause of the …
Run Code Online (Sandbox Code Playgroud)

python sql-server django django-pyodbc django-pyodbc-azure

5
推荐指数
1
解决办法
4337
查看次数

django-pyodbc-azure - 如何使用模式

我正在使用 django-pyodbc-azure ( https://github.com/michiya/django-pyodbc-azure ),一切正常。但是,当我迁移模型时,会在 SQL Server 数据库上创建一个名为“dbo”的新架构。我想使用已经存在的“sp”模式,有什么方法可以设置工作模式?

提前致谢。

django django-pyodbc django-pyodbc-azure

3
推荐指数
1
解决办法
2704
查看次数

使用django连接到旧的informix数据库

我正在尝试使用Django连接到现有的Informix数据库,我使用django-pyodbc-azure通过odbc处理连接,在python解释器中尝试时连接工作正常:

>>>import pyodbc 
>>>conn = pyodbc.connect('DSN=test_ifx;UID=test;PWD=test')
>>>curs = conn.cursor()
>>>curs.execute("select * from someTable")
<pyodbc.Cursor object at 0x0052E520>
Run Code Online (Sandbox Code Playgroud)

所以这项工作很好但是在django中我创建了这样的数据库连接参数:

DATABASES = {
    'default' : {
        'ENGINE' : 'sql_server.pyodbc',
        'NAME' : 'test',
        'USERNAME' : 'test',
        'PASSWORD' : 'test',
        'PORT' : '1260',
        'OPTIONS':{
            'dsn' : 'test_ifx'
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

因此,当我启动服务器时,我收到以下错误:

Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x0353DED0>
Traceback (most recent call last):
  File "C:\Users\PatrickStewball\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\db\backends\base\base.py", line 216, in ensure_connection
    self.connect()
  File "C:\Users\PatrickStewball\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\db\backends\base\base.py", line 194, in connect
    self.connection = self.get_new_connection(conn_params)
  File "C:\Users\PatrickStewball\AppData\Local\Programs\Python\Python37-32\lib\site-packages\sql_server\pyodbc\base.py", …
Run Code Online (Sandbox Code Playgroud)

django informix pyodbc django-pyodbc django-pyodbc-azure

1
推荐指数
1
解决办法
283
查看次数