When you want to have objects in different databases in the same server have SQL interactions, you use one engine and then schema-qualify the tables using the "schema" argument:
https://docs.sqlalchemy.org/en/14/core/metadata.html#specifying-the-schema-name if OTOH you are talking about two entirely separate MySQL servers, MySQL does not have good options in this area, the best you could do would be something like federated storage: https://dev.mysql.com/doc/refman/8.0/en/federated-storage-engine.html but this is not a "normal" thing for most people. On Sun, Mar 14, 2021, at 4:23 AM, [email protected] wrote: > > Hi all, > > I highly appreciate your help with the following issue. > > I have two different databases in MySQL let say db1 and db2. I want to add a > foreign key constraint from table db1.tablex to table db2.tabley and also > include the corresponding relationship in the declarative mapping. I have to > create two different engines for this purpose. But I don't know how to > connect the engines and establish a relationship between these engines. I > also don't know how to define the constraint such that alembic detect the > constraint and apply to the databases. > > -- > 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 [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/sqlalchemy/dfa90791-54d6-47b8-aea7-cfb555039ca1n%40googlegroups.com > > <https://groups.google.com/d/msgid/sqlalchemy/dfa90791-54d6-47b8-aea7-cfb555039ca1n%40googlegroups.com?utm_medium=email&utm_source=footer>. -- 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 [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/sqlalchemy/283d1641-d52f-4c94-a9a8-6255b8b87d9a%40www.fastmail.com.
