Hi.
I have two database schemas, with a table from each I would like to join.
The classes for one schema have been created as explicit declarative
Bases, while the classes for the other were all created via automap Base.
I have a foreign key joining the two tables. Sqlalchemy sees the foreign
key, yet does not recognize it or use. Upon import of my Classes, I'm
getting this error
NoForeignKeysError: Could not determine join condition between parent/child
tables on relationship Cube.target - there are no foreign keys linking
these tables. Ensure that referencing columns are associated with a
ForeignKey or ForeignKeyConstraint, or specify a 'primaryjoin' expression.
datadb.Cube is my declarative base and sampledb.MangaTarget is an automap
base. Here are the foreign keys on datadb.Cube
In [4]: datadb.Cube.__table__.foreign_keys
Out[4]:
{ForeignKey(u'mangadatadb.ifudesign.pk'),
ForeignKey(u'mangasampledb.manga_target.pk'),
ForeignKey(u'mangadatadb.pipeline_info.pk'),
ForeignKey(u'mangadatadb.wavelength.pk')}
I've created the relationship via
Cube.target = relationship(sampledb.MangaTarget, backref='cubes')
I've also tried explicitly adding a foreign_keys=[Cube.manga_target_pk]
here, but that didn't work either.
I initially created the constraint in my schema table with
ALTER TABLE ONLY mangadatadb.cube
ADD CONSTRAINT manga_target_fk
FOREIGN KEY (manga_target_pk) REFERENCES mangasampledb.manga_target(pk)
ON UPDATE CASCADE ON DELETE CASCADE;
Can a relationship be created on a foreign key between a declarative base
class and an automap base class?
I tested out the relationships with an explicit declarative Base class for
MangaTarget and everything works perfectly. However, explicitly declaring
all the tables in my sampledb schema is not really an option,
unfortunately. I'm at a loss here.
If it should be possible, is there a procedure somewhere documented on how
to get that working?
Thanks for any help.
Cheers, Brian
--
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 post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.