django ORM
安装
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple django==2.2
pip install pymysql #django 使用pymysql作为数据库连接引擎
配置
#__init__.py
#使用pymysql 替代mysqlDB作为mysql 引擎
import pymysql
pymysql.install_as_MySQLdb()
#settings.py
DATABASES = { "default": { "ENGINE": "django.db.backends.mysql", "NAME": "devops", "USER": "actor", "PASSWORD": "xxxx", "HOST": "10.1.1.2", "PORT": "3306", } }
定义数据库表
#models.py
from django.db import models # Create your models here. class Person(models.Model): first_name = models.CharField(max_length=30) last_name = models.CharField(max_length=30)
创建表
python manage.py makemigrations #生成配置
python manage.py migrate #将配置在数据库中生效
pycharm 本地创建一个数据库的连接引擎(客户端)