SQLAlchemy 反向生成 model 模型

前言

Django 反向生成的 model 模型的命令 :  python manager.py inspectdb

SQLAlchemy / Flask-SQLAlchemy则是: pip3 install sqlacodegen

使用方法如下

        利用 sqlacodegen 自动生成ORM实体类

..Anaconda3envspy3Scripts>.sqlacodegen.exe --outfile project_pathmod.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)

博客搬运地址

  1. 利用sqlacodegen自动生成ORM实体类
  2. Python3 sqlacodegen 根据已有数据库生成 ORM 使用的 model.py
原文地址:https://www.cnblogs.com/clement-jiao/p/10007846.html