Hi, I don't think that the solution can come from SQLAlchemy. You may have to create a database link between your two databases to be able to query both of them with a single instruction...
Best regards, Thierry 2016-02-23 11:43 GMT+01:00 Mehdi <mese1...@gmail.com>: > Hi > Is it possible two have a one-to-many or many-to-many relationship between > two models which they are exist in two different databases? > I have two oracle dbs on two different machines on lan. so i've created > two engines like: > main_engine = create_engine("oracle://user:pass@ip1/sid") > entry_engine = create_engine("oracle://user:pass@ip2/sid") > > Then i've created two different bases for my models and a session: > meta_data = MetaData() > DBSession = > scoped_session(sessionmaker(extension=ZopeTransactionExtension())) > MainBase = declarative_base(cls=ModelBase, metadata=meta_data) > EntryBase = declarative_base(cls=ModelBase, metadata=meta_data) > > MainBase.metadata.bind = main_engine > EntryBase.metadata.bind = entry_engine > > And let's say i have two simple models like: > class WeatherStation(MainBase): > __tablename__ = "weather_stations" > master_code = Column(NUMBER(10), primary_key=True) > name = Column(String(50), index=True) > evaporation_data = relationship("EvaprationData", backref="station") > and the other one: > class EvaporationData(Base): > __tablename__ = "evaporations_data" > id = Column(NUMBER(30), Sequence("evaporation_data_eid_seq"), > primary_key=True) > station_code = Column(NUMBER(10, 0), > ForeignKey("weather_stations.master_code")) > * each classes defined in separate files models folder. > > Now if i comment out the relationships queries works fine. but with > relationships between my models, i've got errors like: > failed to locate a name ("name 'EvaporationData' is not defined"). If this > is a class name, consider adding this relationship() to the <class > 'measurement.models.weather_station.WeatherStation'> class after both > dependent classes have been defined. > > So is there any solution? > Thank. > > -- > 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 post to this group, send email to sqlalchemy@googlegroups.com. > Visit this group at https://groups.google.com/group/sqlalchemy. > For more options, visit https://groups.google.com/d/optout. > -- http://www.imagesdusport.com -- http://www.ztfy.org -- 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 post to this group, send email to sqlalchemy@googlegroups.com. Visit this group at https://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/d/optout.