-
First Check
Commit to Help
Example Codebranch_id: Optional[int] = Field(
sa_column=Column("branch_id", Integer, ForeignKey("branch.id")),
) DescriptionHow to use sa_column with foreignkey? Operating SystemmacOS Operating System DetailsNo response SQLModel Version0.0.6 Python Version3.9.3 Additional ContextNo response |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments
-
Your code looks correct except I don't believe you need the In general it's hard to debug issues like this with such little info, you should provide more info about the class that contains this field as well as the class you are linking to, or a minimal example that reproduces the issue not using your code. |
Beta Was this translation helpful? Give feedback.
-
When I run alembic there's no foreignkey in branch_id but when i use foreign_key parameter of the field, it will add the fk_contraints |
Beta Was this translation helpful? Give feedback.
-
same to this screenshot it removes my foreignkey when I use sa_column=Column(ForeignKey). But if i use foreign_key in Field class, fk was added. but when when I use Column it removes my foreignkey, I just to add onupdate="CASCADE" to my column. |
Beta Was this translation helpful? Give feedback.
-
The branch_id Field should be set in the model which "table=True"
|
Beta Was this translation helpful? Give feedback.
The branch_id Field should be set in the model which "table=True"