我问了一个问题(Alembic - sqlalchemy initial migration) env.py文件它似乎工作正常,但它没有检测到实际存在的表,因此它会创建包含所有表的迁移文件,例如:蒸馏器 - SQLAlchemy的不我已经导入我的模型后,使用</p> <pre><code>target_metadata = Base.metadata </code></pre> <p>为</p> <pre><code>alembic revision --autogenerate -m "initial migration" </code></pre> <p>检测如何检测表中的现有表
def upgrade():
### commands auto generated by Alembic - please adjust! ###
op.create_table('Brand',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('name', sa.String(), nullable=True),
sa.Column('slug', sa.String(), nullable=True),
sa.Column('date_created', sa.DateTime(), nullable=True),
sa.Column('date_updated', sa.DateTime(), nullable=True),
sa.PrimaryKeyConstraint('id'),
schema='Products'
)
def downgrade():
### commands auto generated by Alembic - please adjust! ###
op.drop_table('ProductFile', schema='Products')
我已经试过:
alembic stamp head
,但运行和运行自动生成命令后,系统再次产生的所有车型。
from project.apps.users.models import *
from project.apps.orders.models import *
from project.apps.products.models import *
from project.base import Base, metadata
# this is the Alembic Config object, which provides
# access to the values within the .ini file in use.
config = context.config
# Interpret the config file for Python logging.
# This line sets up loggers basically.
fileConfig(config.config_file_name)
# add your model's MetaData object here
# for 'autogenerate' support
# from myapp import mymodel
target_metadata = Base.metadata
我该如何避免这个问题?
编辑:
ENV.py:
https://gist.github.com/pypetey/bb65807ce773d8baeaf1
我放弃了DB跑迁移
(env) D:\projekty\test>alembic revision --autogenerate
INFO [alembic.migration] Context impl MSSQLImpl.
INFO [alembic.migration] Will assume transactional DDL.
INFO [alembic.autogenerate.compare] Detected added table u'Users.Country'
INFO [alembic.autogenerate.compare] Detected added table u'Products.Brand'
INFO [alembic.autogenerate.compare] Detected added table u'Users.User'
INFO [alembic.autogenerate.compare] Detected added table u'Products.Product'
INFO [alembic.autogenerate.compare] Detected added table u'Products.ProductFile
'
INFO [alembic.autogenerate.compare] Detected added table u'Orders.Order'
INFO [alembic.autogenerate.compare] Detected added table u'Products.Category'
INFO [alembic.autogenerate.compare] Detected added table u'Products.Review'
INFO [alembic.autogenerate.compare] Detected added table u'Users.UserAddress'
INFO [alembic.autogenerate.compare] Detected added table u'Orders.OrderItem'
INFO [alembic.autogenerate.compare] Detected added table u'Orders.OrderStatus'
Generating D:\projekty\test\alembic\versions\1c6337c144a7_.py ... done
(env) D:\projekty\test>alembic upgrade head
INFO [alembic.migration] Context impl MSSQLImpl.
INFO [alembic.migration] Will assume transactional DDL.
INFO [alembic.migration] Running upgrade None -> 1c6337c144a7, empty message
(env) D:\projekty\test>alembic revision --autogenerate
INFO [alembic.migration] Context impl MSSQLImpl.
INFO [alembic.migration] Will assume transactional DDL.
INFO [alembic.autogenerate.compare] Detected added table u'Users.Country'
INFO [alembic.autogenerate.compare] Detected added table u'Products.Brand'
INFO [alembic.autogenerate.compare] Detected added table u'Users.User'
INFO [alembic.autogenerate.compare] Detected added table u'Products.Product'
INFO [alembic.autogenerate.compare] Detected added table u'Products.ProductFile
'
INFO [alembic.autogenerate.compare] Detected added table u'Orders.Order'
INFO [alembic.autogenerate.compare] Detected added table u'Products.Category'
INFO [alembic.autogenerate.compare] Detected added table u'Products.Review'
INFO [alembic.autogenerate.compare] Detected added table u'Users.UserAddress'
INFO [alembic.autogenerate.compare] Detected added table u'Orders.OrderItem'
INFO [alembic.autogenerate.compare] Detected added table u'Orders.OrderStatus'
Generating D:\projekty\test\alembic\versions\5abb204549f_.py ... done
'alembic current'返回什么? – dgilland 2014-10-09 14:54:07
您是否尝试过首先在空数据库上运行迁移?通过运行'alembic revision --autogenerate ...',编辑迁移文件(如有必要),运行'alembic upgrade head',并再次运行'alembic revision --autogenerate ...'以确认生成空的迁移文件? – dgilland 2014-10-09 14:56:34
@dgilland我crecreated分贝,跑了迁移,并再次运行自动生成。它没有帮助。检查我更新的帖子。 – Efrin 2014-10-10 10:38:29