sqlalchemy.exc.UnboundExecutionError:表对象'负责人'未绑定到引擎或连接

时间:2017-07-11 21:59:45

标签: python sqlalchemy

我尝试使用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()

2 个答案:

答案 0 :(得分:3)

您需要提供engineconnection

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)

相关问题