gpt4 book ai didi

python - python 3中的SQLAlchemy ER图

转载 作者:太空狗 更新时间:2023-10-29 22:24:47 26 4
gpt4 key购买 nike

有谁知道在 python 3 中从 SQLAlchemy 模型制作 ER 图的方法。我找到了 sqlalchemy_schemadisplay,它是 python 2,因为 pydot 和 ERAlchemy 也只是 python 2。

最佳答案

你可以试试eralchemy .

import matplotlib.pyplot as plt
import matplotlib.image as mpimg
import pandas as pd
from eralchemy import render_er

from sqlalchemy import (MetaData, Table, Column)
metadata = MetaData()

# create your own model ....
users = Table('users', metadata,
Column('user_id', Integer(), primary_key=True),
Column('username', String(15), nullable=False, unique=True),
)
orders = Table('orders', metadata,
Column('order_id', Integer()),
Column('user_id', ForeignKey('users.user_id')),
)
# add your own table ....

# Show ER model from here
filename = 'mymodel.png'
render_er(metadata, filename)
imgplot = plt.imshow(mpimg.imread(filename))
plt.rcParams["figure.figsize"] = (15,10)
plt.show()

然后它显示模型。

enter image description here

我使用的那些模块是:

<知识库> 软件 版本
Python 3.4.5 64bit
IPython 5.1.0
操作系统Windows 10
sqlalchemy1.1.5
炼金术1.1.0
matplotlib 2.0.0

关于python - python 3中的SQLAlchemy ER图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44981986/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com