安装
pip install sqlacodegen
使用
sqlacodegen postgresql:///some_local_db sqlacodegen mysql+pymysql://user:password@localhost/dbname sqlacodegen sqlite:///database.db ?
帮助
sqlacodegen --help ?
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) ?
导出全部表
sqlacodegen --outfile=models.py mysql+pymysql://root:password@127.0.0.1:3306/test
导出指定表
sqlacodegen --outfile=models.py mysql+pymysql://root:password@127.0.0.1:3306/test --tables teacher,student
|