Django 反向生成的 model 模型的命令 : python manager.py inspectdbpython
SQLAlchemy / Flask-SQLAlchemy則是: pip3 install sqlacodegenmysql
利用 sqlacodegen 自動生成ORM實體類git
..\Anaconda3\envs\py3\Scripts>.\sqlacodegen.exe --outfile project_path\mod.py mysql+pymysql://Username:Password@IP/database_name
善用選項: --help ! usage: sqlacodegen [-h] [--version] [--schema SCHEMA] [--tables TABLES] [--noviews] [--noindexes] [--noconstraints] [--nojoined] [--noinflect] [--noclasses] [--outfile OUTFILE] [url] Generates SQLAlchemy model code from an existing database. positional arguments: url SQLAlchemy url to the database optional arguments: -h, --help show this help message and exit # 顯示此幫助消息並退出 --version print the version number and exit # 打印版本號並退出 --schema SCHEMA load tables from an alternate schema # 從備用模式加載表 --tables TABLES tables to process (comma-separated, default: all) # 要處理的表(逗號分隔,默認值:所有) --noviews ignore views # 忽略視圖 --noindexes ignore indexes # 忽略索引 --noconstraints ignore constraints # 忽略約束 --nojoined don't autodetect joined table inheritance # 不要自動檢測鏈接表繼承 --noinflect don't try to convert tables names to singular form # 不要嘗試將表名轉換爲單數形式 --noclasses don't generate classes, only tables # 不生成類,只生成表 --outfile OUTFILE file to write output to (default: stdout) # 將輸出寫入的文件(默認值:stdout)