问题
I am using Flask-SQLAlchemy to recreate tables in an existing SQL Server database. The usual declarative base wasn't working out so I am trying to use the automap base.
My DB has a table called 'orders' and I am trying to query the data:
db = SQLAlchemy(app)
db.Model.metadata.reflect(bind=db.engine)
Base = automap_base()
Base.prepare(db.engine, reflect=True)
db.session.query(Base.classes.orders).all()
However, an ArgumentError is thrown:
ArgumentError: orders.orders and back-reference orders.orders_collection are both of the same direction symbol('ONETOMANY'). Did you mean to set remote_side on the many-to-one side ?
The SQLAlchemy doc tells me that the latter orders.orders_collection is automatically created. What could I do to make sure the creation of this collection doesn't lead to this ArgumentError?
来源:https://stackoverflow.com/questions/41064015/sqlalchemys-automap-base-creates-bad-collections-for-one-to-many-tables