0

I am new to Python ORM world. I wanted to generate model (code) from the existing database in Alembic or SQLAlchemy. I could find any docs about that. Just simply having already created database, I would like Alembic to generate me classes for that database for each table. Is there any way to achieve this?

  • 1
    Isn't Alembic a tool for migrations? This sounds more like a job for something like SQLalchemy, but i'm not sure it can do this. – Kraay89 May 04 '21 at 09:38
  • @Kraay89 I'm looking something which is available in .net ef core - scaffolding - code generation for existing database. – Jerzy Stachera May 04 '21 at 09:43

1 Answers1

0

Alembic is used for migration. You can read more about it here Alembic Project Description
SQLAlchemy is an ORM that translates Python classes to tables on relational databases not vice versa.
This online tool create-class-from-database-table may help you to get classes from database tables

Poonam Adhav
  • 382
  • 3
  • 10
  • it is not compatibile code with SQLAlchemy – Jerzy Stachera May 04 '21 at 10:52
  • correct. like I mentioned SQLAlchemy translates Python classes to tables on relational databases not vice versa. This is done using [Declarative Mapping](https://docs.sqlalchemy.org/en/14/orm/mapping_styles.html#orm-declarative-mapping) – Poonam Adhav May 04 '21 at 11:13
  • i think this is huge gap in functionality when working with existing database. EF core has got this out of the box. Scaffolding saves a lot of time, especially for large database with around hundred of tables and probably thousands of columns and indices. – Jerzy Stachera May 04 '21 at 14:39