10

I'm trying to migrate a table with SQLAlchemy Migrate, but I'm getting this error:

sqlalchemy.exc.UnboundExecutionError: Table object 'responsibles' is not bound to an Engine or Connection.  Execution can not proceed without a database to execute against.

When I run:

python manage.py test

This is my migration file:

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()
Filipe Ferminiano
  • 8,373
  • 25
  • 104
  • 174

2 Answers2

11

did you create your engine? like this

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

and then do

meta.bind = engine meta.create_all(engine)

developer_hatch
  • 15,898
  • 3
  • 42
  • 75
6

You need to supply engine or connection

sqlalchemy.schema.MetaData.bind

For e.g.:

engine = create_engine("someurl://")
metadata.bind = engine
vishes_shell
  • 22,409
  • 6
  • 71
  • 81