How to update foreign-key constraints changed when Alembic cannot detect them? #1350
Replies: 2 comments 1 reply
-
Hi,
|
Beta Was this translation helpful? Give feedback.
-
I don't want to hijack this thread but I think I am also having this issue - alembic appears not to detect Foreign key changes, or foreign keys at all in my case. I know this was an issue in some earlier versions of alembic, but according to the docs, foreign keys should be automatically handled. I have a table called fk_signup_code: Mapped[Optional[str]] = mapped_column(
ForeignKey("signup_codes.code", name="fk_signup_code")
) when I change the FK to point at a different column in the other table: fk_signup_code_id: Mapped[Optional[str]] = mapped_column(
ForeignKey("signup_codes.id", name="fk_signup_code_id")
) running
So it's correctly detecting the change in column name but not the foreign key. If I don't change the column name, it doesn't detect any changes. I'm using alembic 1.13.1. Is this expected behaviour @CaselIT ? Thanks |
Beta Was this translation helpful? Give feedback.
-
I have two models looking like this:
With current models, they prevent me from updating
short_name
in raw SQL due to violation of foreign key constraint ofschool_short_name
. I want to update it on schema level by adding these options:However,
alembic
does not detect these constraint changes. When I need to update something related toshort_name
, I need to manually drop the constraints and re-add them again, which is tedious because I have many other relations like these. Is there anyway I can achieve this with Python and Alembic?Beta Was this translation helpful? Give feedback.
All reactions