我正在尝试使用 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)
你创造了你的引擎吗?像这样
engine = create_engine('sqlite:///:memory:')
然后做
meta.bind = engine
meta.create_all(engine)
您需要提供engine
或connection
sqlalchemy.schema.MetaData.bind
例如:
engine = create_engine("someurl://")
metadata.bind = engine
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
3977 次 |
最近记录: |