赞
踩
1、通过pip安装peewee
pip install peewee
2、导出表结构,自动生成model
python -m pwiz -e mysql -H localhost -p 3306 -u root -P -t tb_address,bt_user vo_erp > models.py
db=MySQLDatabase("vo_erp_test",host="localhost",port=3306,user="root",password="123456") class BaseModel(Model): class Meta: database=db class Person(BaseModel): id=IntegerField(primary_key=True) first_name=CharField() last_name=CharField() age=IntegerField() class Meta: table_name="bt_person_info" database=db class Pet(BaseModel): id=IntegerField(primary_key=True) type=CharField() name=CharField() # master_id=ForeignKeyField(Person,related_name="pet_master") master_id=IntegerField() class Meta: table_name="bt_pet_info" class Address(BaseModel): id=IntegerField(primary_key=True) type
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。