Reputation: 3898
I am trying to get SQLAlchemy to autoload my table columns (using MySQL, if that matters). I have:
DBSession = scoped_session(sessionmaker(extension=ZopeTransactionExtension()))
Base = declarative_base()
class User(object):
__tablename__ = 'users'
__table_args__ = {'schema': 'users', 'autoload': True}
Here is my error:
InvalidRequestError: SQL expression, column, or mapped entity expected - got '<class 'myproject.models.User'>'
I added an __init__
function, and still get the same error:
def __init__(self,col1,col2):
self.col1 = col1
self.col2 = col2
Upvotes: 1
Views: 1401
Reputation: 12417
Your User
class should have Base
as its parent, not object
:
DBSession = scoped_session(sessionmaker(extension=ZopeTransactionExtension()))
engine = create_engine(db_string, echo=db_echo)
Base = declarative_base()
Base.metadata.bind = engine
class User(Base):
__tablename__ = 'users'
__table_args__ = {'schema': 'users', 'autoload': True}
Upvotes: 3