sqlalchemy / sqlalchemy/alembic

take use_alter=True, other FK / foreign key / foreignkey constraint rules into account when autogenerating create_table / drop_table

Open
#326 20 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

autogenerate - rendering bug open for pull requests recursive FK issue Tier 1
Dominant language
Python
Stars
4.4k
Forks
375
PR merge metrics
No merged PRs in 30d

Description

Migrated issue, originally created by Adrian Vogelsgesang (@vogelsgesang)

If the schema contains circular dependencies, the order of the CREATE TABLE statements is incorrect.

This is because metadata.sorted_tables (used here) returns the tables ordered alphabetically if there are circular dependencies.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in alembic/autogenerate/compare.py at the use of metadata.sorted_tables and trace how circular foreign-key dependencies affect create_table and drop_table generation. Review the handling of use_alter and related foreign-key rules; done means autogenerated statements respect those rules instead of falling back to alphabetical ordering for circular dependencies.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, sqlalchemy
Domain
databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.