Files
fcb_photo_review/auto_generator.py
2024-05-17 16:16:56 +08:00

15 lines
474 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 自动生成数据库表和sqlalchemy对应的Model
import subprocess
from config.mysql import DB_URL
table = input("请输入表名:")
out_file = f"photo_review/entity/{table}.py"
command = f"sqlacodegen {DB_URL} --outfile={out_file} --tables={table}"
try:
subprocess.run(command, shell=True, check=True)
print(f"{table}.py文件生成成功请手动调整Base的声明")
except Exception as e:
print(f"生成{table}.py文件时发生错误: {e}")