Skip to content
Discussion options

You must be logged in to vote

The exception is telling you that the factory is creating a second ORM mapping for the same (schema, table_name) inside the same MetaData. That is different from the database table already existing: SQLAlchemy normally expects one in-memory Table identity per name in a MetaData collection.

I would not use extend_existing=True to make repeated model-class creation the normal path. It can merge new Table(...) arguments into the existing metadata object, but it does not turn two separately generated ORM classes into one coherent mapping, and it does not migrate the physical database schema. SQLAlchemy documents that distinction here:

https://docs.sqlalchemy.org/en/20/core/metadata.html#sqlal…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by Louisfrn
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
2 participants