我尝试使用SQLAlchemy Migrate迁移表,但我收到此错误:
sqlalchemy.exc.UnboundExecutionError: Table object 'responsibles' is not bound to an Engine or Connection. Execution can not proceed without a database to execute against.
当我跑步时:
python manage.py test
这是我的迁移文件:
from sqlalchemy import *
from migrate import *
meta = MetaData()
responsibles = Table(
'responsibles', meta,
Column('id', Integer, primary_key=True),
Column('breakdown_type', String(255)),
Column('breakdown_name', String(500)),
Column('email', String(255)),
Column('name', String(255)),
)
def upgrade(migrate_engine):
# Upgrade operations go here. Don't create your own engine; bind
# migrate_engine to your metadata
responsibles.create()
def downgrade(migrate_engine):
# Operations to reverse the above upgrade go here.
responsibles.drop()
答案 0 :(得分:3)
您需要提供engine
或connection
sqlalchemy.schema.MetaData.bind
例如:
engine = create_engine("someurl://")
metadata.bind = engine
答案 1 :(得分:3)
engine = create_engine('sqlite:///:memory:')
然后再做
meta.bind = engine
meta.create_all(engine)