安装 pip3 install peewee pip3 install pymysql http://docs.peewee-orm.com/en/latest/peewee/models.html 快速使用 import datetime from peewee import * # db = SqliteDatabase('my_app.db') db = MySQLDatabase('peewee', host='127.0.0.1', user='root', password='asd123...') class User(Model): username = CharField(unique=True) class Meta: database = db class Tweet(Model): user = ForeignKeyField(User, backref='tweets') message = TextField() created_date = DateTimeField(default=datetime.datetime.now) is_published = BooleanField(default=True) class Meta: database = db if __name__ == '__main__': # 生成表结构 db.connect()