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

Fil*_*ano 9 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.
Run Code Online (Sandbox Code Playgroud)

当我运行时:

python manage.py test
Run Code Online (Sandbox Code Playgroud)

这是我的迁移文件:

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()
Run Code Online (Sandbox Code Playgroud)

Dam*_*ero 9

你创造了你的引擎吗?像这样

engine = create_engine('sqlite:///:memory:')

然后做

meta.bind = engine meta.create_all(engine)


vis*_*ell 6

您需要提供engineconnection

sqlalchemy.schema.MetaData.bind

例如:

engine = create_engine("someurl://")
metadata.bind = engine
Run Code Online (Sandbox Code Playgroud)