【问题标题】:How to configure the Database setting Django-MSSQL (windows)?如何配置数据库设置 Django-MSSQL (windows)?
【发布时间】:2018-11-01 13:25:10
【问题描述】:

我是 Django 新手,目前正在尝试使用 python 3.6.4 和 Django2.1.2 将我的项目与 SQL 服务器连接起来,我尝试了多个驱动程序连接器 (libraries installed),

> (irisha) C:\Users\MOHMMED-PC\Desktop\SOUS BUREAU\WEB\irisha\src>pip freeze
adodbapi==2.6.0.7
Django==2.1.2
django-mssql==1.8
django-pyodbc==1.1.3
django-pyodbc-azure==2.1.0.0
django-sqlserver==1.11
pyodbc==4.0.24
pypyodbc==1.3.4
python-tds==1.9.1
pytz==2018.6
six==1.11.0

但没有结果,我使用的最后一个驱动程序连接器是 pyodbc: Settings,

DATABASES = {
'default': {
    'ENGINE': 'sql_server.pyodbc',
    'NAME': 'iristest',
    'USER': 'sa',
    'PASSWORD': '1234',
    'HOST': '127.0.0.1\test',
    'PORT': '1433',


},}

但出现了一些错误:errors

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

感谢您帮助我找到解决方案。

【问题讨论】:

  • 在您提出的上一个问题中,我们已经评论说您应该过去 code,而不是 not images 的代码。
  • 我把代码放了。
  • 主机中包含非转义的反斜杠,写'HOST': r'127.0.0.1\test',怎么办?
  • 同样的错误再次出现

标签: python sql-server django python-3.x django-models


【解决方案1】:

“如果您使用 SQLite 以外的数据库,请确保此时您已经创建了一个数据库。使用“CREATE DATABASE database_name;”执行此操作在数据库的交互式提示中。”

More about database setup

【讨论】:

    【解决方案2】:

    最后,我得到了解决方案,问题在于 Django 和 python 之间的兼容性,当我将 pyodbc 与 Python 3.4.4 和 Django==1.8.19 一起使用时,它起作用了,这就是我所做的:

    -安装 Python 3.4.4 - 2015-12-21

    在cmd中

    pip 安装 virtualenv 测试

    虚拟环境测试

    .\脚本\激活

    pip install Django==1.8.19 pip install django-mssql

    点安装https://www.lfd.uci.edu/~gohlke/pythonlibs/#pywin32

    django-admin 启动项目 myproject 。

    修改设置数据库

    > DATABASES = {    'default': {
    >        'ENGINE': 'sqlserver_ado',
    >        'HOST': 'MOHAMMED-PC\SQL2014',  # Replace with host name where you have MSSQL server running
    >        'NAME': 'test',  # Replace with name of the database on the MSSQL server
    >        'USER': 'sa',  # Replace with user name
    >        'PASSWORD': '1234',  # Replace with password    }, }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-04-14
      • 2012-06-19
      • 2013-12-16
      • 2020-08-13
      • 2010-09-29
      • 2019-08-27
      • 2018-06-07
      相关资源
      最近更新 更多