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
userandcurrencytable. Both tables may havecreated_byfield with the reference tousertable, andusertable may havecurrency_idfield with the reference to thecurrencytable.In my
env.pyI have the followingprocess_revision_directivessnippet which essentially moves FKs declarations from table declarations, move them to the end ofupgradefunction in the migration script, and then adds the same FKs to the beginning ofdowngradescript. 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