Created
June 4, 2019 08:28
-
-
Save 2minchul/c979feb11c2dcbb79818f2cb97dbee17 to your computer and use it in GitHub Desktop.
sqlacodegen을 python으로 실행하여 models.py 만들기
This file contains hidden or 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 hidden or 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment