Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to reverse engineer data models from an existing database in Python and SQL-Alchemy [duplicate]

I understand that there is a db migration process to create databases/tables using SQL-Alchemy. But I am looking for the reverse. DBAs will create and manage Data definitions and they don't want to manage it through python code. So assuming that model, if an existing database schema (in postgresql) is defined how can I create the data model for that schema in SQL Alchemy (without actually typing out every class)? Is there a reverse engineering tool that people recommend to accomplish this task?

I've tried sqlacodegen 1.1.5 but it doesn't seem to produce the right python files for foreign key relationships in tables.

Any suggestions will be greatly appreciated.

like image 714
RG1980 Avatar asked Mar 05 '15 19:03

RG1980


1 Answers

I used sqlacodegen 1.1.6: https://pypi.python.org/pypi/sqlacodegen.

It works, generates the python script with all classes, and relationship tables for many to many relationship.

like image 140
Yingbo Miao Avatar answered Oct 15 '22 04:10

Yingbo Miao