Skip to content

Error with Relationships: Foreign key associated with column [...] could not find table #798

Discussion options

You must be logged in to vote

EDIT:
I'm leaving the below in place for posterity, but I think the actual solution is simpler and I had some major misunderstandings when I wrote it. When you create a MetaData object and use it to set properties on the tables, it interferes with any calls that go via SQLModel.metadata, which is referencing its own MetaData object stored in a class variable on SQLModel. The simplest way to set the schema is to call

SQLModel.metadata.schema = "your-schema-name"

BEFORE the models are imported.

As an aside, I don't have a neat solution for controlling this dynamically. This blog post describes how to do it in SQLAlchemy, but Base.metadata seems to behave differently from SQLModel.metadata i…

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
2 replies
@betterthanever2
Comment options

@charlie-corus
Comment options

Answer selected by betterthanever2
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
3 participants