peewee是一个轻量级的ORM框架,适用于小型项目
要使用首先的现在安装peewee模块:
C:\Users\asus>pip3 install peewee
Collecting peewee
Downloadinghttps://files.pythonhosted.org/packages/33/07/d4c742d88998fb448e18be41dc25e748376b7f69359d37fedaee09e66617/peewee-3.5.2.tar.gz 1.9MB)100% |████████████████████████████████| 1.9MB 13kB/s
Installing collected packages: peewee
Running setup.py install for peewee ... done Successfully installed peewee-3.5.2
安装完成之后,要使用peewee操作数据库得先import
连接数据库并创建table
from peewee import MySQLDatabase, Model, CharField, DateField, BooleanField, IntegerField
#py_peewee连接的数据库名
db = MySQLDatabase('py_peewee', host='192.168.1.103', user='root', passwd='mysql', charset='utf8', port=3306)
class BaseModel(Model):
class Meta: