콘텐츠로 이동
Search

Sqlacodegen

lastmod 2026-11-10created 2024-12-032 edits

sqlacodegen은 기존 데이터베이스에 접속해 테이블, 컬럼, 제약 조건, 외래 키를 읽고 그에 대응하는 SQLAlchemy 모델 코드(declarative 클래스나 Table 정의)를 출력하는 명령행 도구다. 이미 운영 중인 스키마를 Python 코드로 옮길 때 손으로 옮겨 적는 수고와 오타를 줄여 주며, 접속 문자열만 넘기면 되고 MySQL, PostgreSQL, MSSQL 등 SQLAlchemy 가 지원하는 모든 DB 에 쓸 수 있다.

SQLAlchemy에 사용할 테이블(코드)을 자동 생성.

Install

## sqlacodegen
pip install sqlacodegen

## MySQL 사용시
pip install pymysql

## sqlalchemy
pip install sqlalchemy

Examples

sqlacodegen 'mysql+pymysql://username:password@localhost:3307/dbname' > tables.py
sqlacodegen 'mssql+pymssql://username:password@localhost:1433/dbname' > tables.py

See also

Favorite site

author Zer0, MCPBot sitemap