简体   繁体   English

如何配置数据库设置Django-MSSQL(Windows)?

[英]How to configure the Database setting Django-MSSQL (windows)?

I'm new to Django and currently trying to connect my project using python 3.6.4 and Django2.1.2 with SQL server, I tried multiple drivers connectors ( libraries installed ), 我是Django的新手,目前正尝试使用python 3.6.4和Django2.1.2与SQL Server连接我的项目,我尝试了多个驱动程序连接器( 已安装库 ),

> (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

but without result, the last driver connector I used is pyodbc: Settings , 但没有结果,我使用的最后一个驱动器连接器是pyodbc: 设置

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


},}

but some errors appeared: errors 但是出现了一些错误: 错误

django.db.utils.InterfaceError: ('IM002', '[IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified (0) (SQLDriverConnect)') django.db.utils.InterfaceError :(“ IM002”,“ [IM002] [Microsoft] [ODBC驱动程序管理器]数据源名称未找到且未指定默认驱动程序(0)(SQLDriverConnect)”)

thanks for helping me to find a solution. 感谢您帮助我找到解决方案。

"If you're using a database besides SQLite, make sure you've created a database by this point. Do that with “CREATE DATABASE database_name;” within your database's interactive prompt." “如果您使用的是除SQLite之外的数据库,请确保此时已创建数据库。在数据库的交互式提示中使用“ CREATE DATABASE database_name;”进行此操作。

More about database setup 有关数据库设置的更多信息

Finally, I got the solution, the problem is on compatibility between Django and python, when I use pyodbc with Python 3.4.4 and Django==1.8.19 it worked, and this is what I did: 最终,我得到了解决方案,问题出在Django和python之间的兼容性上,当我将pyodbc与Python 3.4.4和Django == 1.8.19一起使用时,它起作用了,这就是我所做的:

-install Python 3.4.4 - 2015-12-21 安装Python 3.4.4-2015-12-21

in cmd 在cmd中

pip install virtualenv test pip安装virtualenv测试

virtualenv test 虚拟环境测试

.\\Scripts\\activate \\脚本\\激活

pip install Django==1.8.19 pip install django-mssql pip install Django == 1.8.19 pip install django-mssql

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

django-admin startproject myproject . django-admin startproject myproject。

modify setting database 修改设置数据库

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM