python 3中的SQLAlchemy ER图 [英] SQLAlchemy ER diagram in python 3

查看:495
本文介绍了python 3中的SQLAlchemy ER图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人知道在python 3中用SQLAlchemy模型制作ER图的方法吗?我发现sqlalchemy_schemadisplay是python 2,因为pydot和ERAlchemy也是python 2。

解决方案

您可以尝试



我使用的那些模块是:




软件 版本

Python 3.4.5 64bit

IPython 5.1。 0

OS Windows 10

sqlalchemy 1.1 .5

矿物化学 1.1.0

matplotlib 2.0.0


Does anyone know a way to make an ER diagram from SQLAlchemy models in python 3. I found sqlalchemy_schemadisplay, which is python 2 because of pydot and ERAlchemy which is also python 2 only.

解决方案

You can try 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()

Then it shows the model.

Those modules I used are:

Software Version
Python 3.4.5 64bit
IPython 5.1.0
OS Windows 10
sqlalchemy 1.1.5
eralchemy 1.1.0
matplotlib 2.0.0

这篇关于python 3中的SQLAlchemy ER图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆