flask 快速生成model

flask-sqlacodegen 快速生成ORM model

  1. 安装依赖 `
pip install flask-sqlacodegen
  1. 使用方法

第一种:此方法是生成指定的表,并且,你的数据库得有建好的表

flask-sqlacodegen "mysql://root:[email protected]/food_db" --tables user --outfile "common/models/user.py"  --flask

“mysql://root:[email protected]/food_db”
此处是连接数据库,必须要双引号包裹,不然,会报错

–tables user
user 是表的名字

“common/models/user.py”
此处是生成文件的位置

第二种:此方法是生成数据库中的所有表,并存在同一个文件下

flask-sqlacodegen "mysql://root:[email protected]/food_db" --outfile "common/models/user.py"  --flask

你可能感兴趣的:(学生党,程序爱好者,flask,python,mysql)