一、初始化pyodbc包 File->Setting->Project->Project Interpreter->添加 pcodbc
二 、初始化django-pyodbc-azure 步骤同上
创建数据库连接:settings.py
DATABASES = { ‘default‘: { ‘ENGINE‘: ‘sql_server.pyodbc‘, ‘NAME‘: ‘DBTest‘, ‘USER‘: ‘sa‘, ‘PASSWORD‘: ‘qazwsx‘, ‘HOST‘: ‘192.168.0.7‘, ‘PORT‘: ‘‘, ‘OPTIONS‘: { ‘driver‘: ‘SQL Server Native Client 11.0‘, ‘MARS_Connection‘: True, }, }, } DATABASE_CONNECTION_POOLING = False
三、PyCharm 创建Application 步骤如下
1、Tools->Run manage.py Task... 显示如下界面
2、执行 startapp AppName 添加了Application
3、app->models.py 添加model
from django.db import models # Create your models here. class userinfo(models.Model): #如果没有models.AutoField,默认会创建一个id的自增列 name = models.CharField(max_length=30) email = models.EmailField() memo = models.TextField()
4、生成相应表
项目文件下目录下执行如下代码:
python manage.py makemigrations python manage.py migrate
或者在 Tools->Run manage.py Task...
makemigrations
migrate
执行成功后查看数据库如下
时间: 2024-09-30 07:03:22