Skip to content

Instantly share code, notes, and snippets.

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