我正在尝试使用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()
最佳答案
您创建引擎了吗?像这样engine = create_engine('sqlite:///:memory:')
然后做meta.bind = enginemeta.create_all(engine)
关于python - sqlalchemy.exc.UnboundExecutionError : Table object 'responsibles' is not bound to an Engine or Connection,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/45045147/