이미 만들어진 DB에서 sqlalchemy Model 생성하기
from sqlalchemy.engine import create_engine | |
from sqlalchemy.schema import MetaData | |
from sqlacodegen.codegen import CodeGenerator | |
url = 'mysql+pymysql://user:password@localhost/dbname' | |
engine = create_engine(url) | |
metadata = MetaData(engine) | |
metadata.reflect(engine) | |
with open('models.py', 'w', encoding='utf-8') as outfile: | |
generator = CodeGenerator(metadata) | |
generator.render(outfile) |
sqlalchemy | |
sqlacodegen |
'Python' 카테고리의 다른 글
Installing mysqlclient for debian stretch (0) | 2017.08.21 |
---|---|
Python3.6 optimize installation for RaspberryPI (0) | 2017.08.21 |
Install Python3.6 on RPI with berryconda (0) | 2017.07.06 |
[python] int to bytes (1) | 2017.02.18 |