Skip to content

Issue with Foreign Key Relationship Across Schemas in SQLAlchemy and Alembic Migrations #1571

Discussion options

You must be logged in to vote

hi -

you are using two separate MetaData collections so there is no string lookup between those two. To retain the use of two separate MetaData collections you need to apply the actual remote Column object to ForeignKey:

from model1 import Model1

class Model2(Base2):
    # ...

    model1_id = Column(Integer, ForeignKey(Model1.id), nullable=False)

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by vedgautam717
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants