The problem of flask sqlalchemy connecting to multiple databases

flask connects two databases, and the secondary database is bound with bind key, so there is no problem with the use of most tables. However, if there is a table with the same name and the structure of the table is different, the result will always be an error. When you report an error in query, you can"t find the field. It feels like the structure of the main database is used to check the data of the secondary database, resulting in the field unknown. There is no good solution. One way is to instantiate a sqlalchemy object and use the new object as the base class for the model of the subdatabase. Is there any good solution?

Apr.09,2021

you can distinguish tables with the same name by specifying _ _ tablename__ .

class A1(db.Model):
    __tablename__='a'
    ...
    
class A2(db.Model):
    __tablename__='a'
    ...
Menu