Hi all! I try to automap my existing database to classes. Between two tables I have multiple join paths and I have trouble managing those properly.
Here's a sample schema from my database: CREATE SCHEMA shop; CREATE TABLE shop.address ( id SERIAL PRIMARY KEY, name text, address text ) CREATE TABLE shop.orders ( id SERIAL PRIMARY KEY, items text, billingaddr_id integer REFERENCES address, shippingaddr_id integer REFERENCES address ); I have declared relationships for those foreign keys as follows: from sqlalchemy import create_enginefrom sqlalchemy.orm import relationship, Sessionfrom sqlalchemy.ext.automap import automap_base engine = create_engine( "postgresql://postgres:postgres@localhost:5432/postgres", future=True ) Base = automap_base() class Order(Base): __tablename__ = 'orders' __table_args__ = {"schema": "shop"} billingaddr = relationship('address', foreign_keys="Order.billingaddr_id", backref="orders_billed") shippingaddr = relationship('address', foreign_keys="Order.shippingaddr_id", backref="orders_shipped") Base.prepare(engine, schema='shop', reflect=True) Address = Base.classes.address Now when creating a new Address object: jack = Address(name='Jack', address='57815 Cheryl Unions') I get a warning: "SAWarning: relationship 'Order.address' will copy column address.id to column orders.shippingaddr_id, which conflicts with relationship(s): 'address.orders_shipped' (copies address.id to orders.shippingaddr_id), 'Order.shippingaddr' (copies address.id to orders.shippingaddr_id). If this is not the intention, consider if these relationships should be linked with back_populates, or if viewonly=True should be applied to one or more if they are read-only. For the less common case that foreign key constraints are partially overlapping, the orm.foreign() annotation can be used to isolate the columns that should be written towards. The 'overlaps' parameter may be used to remove this warning." How should this be solved? That address relationship is the one automap creates automatically and is now messing with me. I don't actually need that anymore since I have created relationships by myself. Can I somehow prevent automap from creating it by default or can I delete created unnecessary relationships? I have tried to set address = None in the class declaration but it didn't work. address relationship is still created. Thanks, Lauri -- SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper http://www.sqlalchemy.org/ To post example code, please provide an MCVE: Minimal, Complete, and Verifiable Example. See http://stackoverflow.com/help/mcve for a full description. --- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/sqlalchemy/CAKWoFMKgPMvdrUd8DCNU99DMp3tLgACie5cpXsqMV_otVuAoag%40mail.gmail.com.