[Python] Alembic trying to delete my tables

Discussão em 'Python' iniciado por Stack, Abril 26, 2025.

  1. Stack

    Stack Membro Participativo

    Alembic beginner here. I'm having some issues with Alembic trying to delete my tables that are already created. I have no idea what is going on. Right now I have a database that looks like this:

    [​IMG]

    If I run alembic upgrade head, I get this as my result:

    INFO [alembic.runtime.migration] Context impl PostgresqlImpl.
    INFO [alembic.runtime.migration] Will assume transactional DDL.


    If I run alembic history, I get this result, which is correct:

    c2659db918a9 -> 765c30f7078c (head), creat table views
    c4a0cac54f89 -> c2659db918a9, Made last_update not null for all tables
    19dd9f3d1d16 -> c4a0cac54f89, Added last_update field defaulted to now
    77c03ebb393b -> 19dd9f3d1d16, Added indexes to each table
    0737825277d8 -> 77c03ebb393b, Change foreign key columns to non-nullable
    5eb3c5f7f599 -> 0737825277d8, Rename a column in daily_etf_underlying table
    0da0b2a43172 -> 5eb3c5f7f599, Add extra_info column to daily_etf_underlying
    c181fe8bcfa9 -> 0da0b2a43172, Make daily_etf id columns nullable
    8fba2675104b -> c181fe8bcfa9, added fixing table
    074563d69c3b -> 8fba2675104b, Modify daily_etf tables
    2c9de57e43f0 -> 074563d69c3b, Add fund_family columns
    80de6fb0a104 -> 2c9de57e43f0, Modify daily_etf table
    a970af9bb117 -> 80de6fb0a104, Add daily_etf_basket, daily_etf_fx_forward tables
    <base> -> a970af9bb117, Add daily_etf table


    But if I run alembic revision --autogenerate -m "<>", I get this!

    alembic revision --autogenerate -m "Raw fidessa client trade table"
    INFO [alembic.runtime.migration] Context impl PostgresqlImpl.
    INFO [alembic.runtime.migration] Will assume transactional DDL.
    INFO [alembic.ddl.postgresql] Detected sequence named 'daily_etf_fx_forward_id_seq' as owned by integer column 'daily_etf_fx_forward(id)', assuming SERIAL and omitting
    INFO [alembic.autogenerate.compare] Detected removed table 'daily_etf_fx_forward'
    INFO [alembic.autogenerate.compare] Detected removed table 'daily_etf'
    INFO [alembic.ddl.postgresql] Detected sequence named 'daily_fx_fixing_rate_id_seq' as owned by integer column 'daily_fx_fixing_rate(id)', assuming SERIAL and omitting
    INFO [alembic.autogenerate.compare] Detected removed table 'daily_fx_fixing_rate'
    INFO [alembic.ddl.postgresql] Detected sequence named 'daily_etf_underlying_id_seq' as owned by integer column 'daily_etf_underlying(id)', assuming SERIAL and omitting
    INFO [alembic.autogenerate.compare] Detected removed table 'daily_etf_underlying'
    Generating C:\dev\Projects\stark_database\stark_database\migrations\versions\86174c06e59e_raw_fidessa_client_trade_table.py ... done


    And my autogenerated file is just trying to remove all my tables :(

    def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_table('daily_fx_fixing_rate')
    op.drop_table('daily_etf_underlying')
    op.drop_table('daily_etf')
    op.drop_table('daily_etf_fx_forward')
    # ### end Alembic commands ###


    What is going on here? Why is alembic trying to delete everything?

    Thanks for your help.

    EDIT: alembic.ini:

    [alembic]
    script_location = migrations
    sqlalchemy.url = postgresql://stark_admin:hpt@localhost/stark


    env.py is exactly textbook to alembic init alembic

    Continue reading...

Compartilhe esta Página