【发布时间】:2017-08-15 14:29:07
【问题描述】:
Alembic 初学者在这里。我在尝试删除我已经创建的表时遇到了一些问题。我不知道发生了什么。现在我有一个看起来像这样的数据库:
如果我运行 alembic upgrade head,我会得到以下结果:
INFO [alembic.runtime.migration] Context impl PostgresqlImpl.
INFO [alembic.runtime.migration] Will assume transactional DDL.
如果我运行alembic history,我会得到这个结果,这是正确的:
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
但如果我运行alembic revision --autogenerate -m "<>",我会得到这个!
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
而我的自动生成文件只是试图删除我所有的表:(
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 ###
这里发生了什么?为什么 alembic 试图删除所有内容?
感谢您的帮助。
编辑:alembic.ini:
[alembic]
script_location = migrations
sqlalchemy.url = postgresql://stark_admin:hpt@localhost/stark
env.py 完全是 alembic init alembic 的教科书
【问题讨论】:
-
你的表元数据和alembic配置怎么样?
-
查看编辑。谢谢伊利亚
-
为了确定,您是否已将 env.py 中的
target_metadata = None替换为指向您的表元数据?
标签: python sqlalchemy alembic