针对于python3快速生成model模型字段,指定在python3以上
安装sqlacodegen
执行命令,生成model.py文件
1
| sqlacodegen --outfile ~/路径/model.py mysql+pymysql:
|
执行实例
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
|
import os
def run():
db_url = "mysql+pymysql://root:123456@192.168.1.252:3306/op_erp_db" tables = "product_attributes"
command = "sqlacodegen --outfile ~/data/htdocs/foreign_way_platform/tools/model.py {db_url} --tables {tables}".format(db_url=db_url, tables=tables) os.system(command)
print("generator model class complete !")
if __name__ == '__main__': run()
|