I am getting an exception:
sqlalchemy.exc.UnboundExecutionError: Could not locate a bind configured on mapper mapped class User->users, SQL expression or this Session.
My engine creation code is in a static method of a class and is as follows:
db_url = 'postgresql+psycopg2://myuser:'\
'mypw@localhost:5432/'\
'mydb'
cls.engine = create_engine(db_url, echo=False)
at the module level I have this function:
def add_user(username, password,
active=True, by=1,
uid=None):
"""Create a User and add it to the database."""
with Session(DatabaseORM.get_engine()) as session:
if uid is not None:
user = User(username=username,
password=password,
active=active,
created_by=by,
uid=uid)
else:
user = User(username=username,
password=password,
active=active,
created_by=by)
session.add(user)
session.commit()
id_ = user.id_
return id_
I tried adding:
session = Session.configure(bind=self.engine)
in the with block but it told me configure is not an attribute of session.
Any help would be appreciated thank you.
- Jason