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 |
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. |
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 |
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. |
|
The branch_id Field should be set in the model which "table=True" |

The branch_id Field should be set in the model which "table=True"