이미 만들어진 DB에서 sqlalchemy Model 생성하기
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |