3
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

SQLAlchemyで既存のDBからモデルを作る方法

Posted at

Djangoならこちらの方法があるんですが
https://docs.djangoproject.com/ja/3.1/howto/legacy-databases/

それ以外の場合に少し困ったのでこちらに備忘録として書いておきます。

sqlacodegen

インストール

pip install sqlacodegen

使用例

sqlacodegenの後にSQLAlchemyで使用するDatabaseURLを記載します。
下記はpostgresqlの例です。

sqlacodegen postgresql://{DB_USER}:{DB_PASSWORD}@{DB_HOST}/{DB_NAME} > models.py
3
9
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?