mysql数据库反向生成 sqlAlchemy
生成代码(make_model.py)
import os
HOST = ''
PORT = 3306
USERNAME = 'root'
PASSWORD = ''
DB = 'data_center'
# Mysql版
DB_URI = f'mysql+pymysql://{USERNAME}:{PASSWORD}@{HOST}:{PORT}/{DB}'
# 自动生成models
os.system(f'sqlacodegen {DB_URI} > models.py')
# # 操作数据句柄
# engine: Engine = create_engine(DB_URI)
# Base = declarative_base(engine)
# session: Session = sessionmaker(engine)()