Feature: decoupling foreign keys (FKs) from table declarations #1205
Replies: 2 comments 2 replies
-
yes it makes sense, the issue to do this feature is #326. SQLAlchemy itself already knows how to do this when you run there's no motivated resources for this issue at this time but we can accept PRs that include tests. it would likely be a very involved feature add and probably should be "opt in" with a flag of some kind to avoid regressions. |
Beta Was this translation helpful? Give feedback.
-
Thanks! I agree about that this feature should be "opt in", totally fine. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
In some cases it's unavoidable to have circular FK dependencies. E.g. let's say we have
user
andcurrency
table. Both tables may havecreated_by
field with the reference touser
table, anduser
table may havecurrency_id
field with the reference to thecurrency
table.In my
env.py
I have the followingprocess_revision_directives
snippet which essentially moves FKs declarations from table declarations, move them to the end ofupgrade
function in the migration script, and then adds the same FKs to the beginning ofdowngrade
script. All in proper order.Here it is:
And I'm wondering is it possible or makes sense to have it built-in in alembic? Thanks!
Beta Was this translation helpful? Give feedback.
All reactions