Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sqlalchemy.exc.UnboundExecutionError: Table object 'responsibles' is not bound to an Engine or Connection

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()
like image 455
Filipe Ferminiano Avatar asked Jul 11 '17 21:07

Filipe Ferminiano


People also ask

What is an Engine in SQLAlchemy?

The Engine is the starting point for any SQLAlchemy application. It's “home base” for the actual database and its DBAPI, delivered to the SQLAlchemy application through a connection pool and a Dialect , which describes how to talk to a specific kind of database/DBAPI combination.

Does SQLAlchemy autocommit?

Explicit Begin Changed in version 1.4: SQLAlchemy 1.4 deprecates “autocommit mode”, which is historically enabled by using the Session.


1 Answers

did you create your engine? like this

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

and then do

meta.bind = engine meta.create_all(engine)

like image 171
A Monad is a Monoid Avatar answered Sep 17 '22 17:09

A Monad is a Monoid