I found my error It was in the logic. Thank you for taking the time to read.
- Jason On Tuesday, May 17, 2022 at 4:51:49 PM UTC-4 Jason Hoppes wrote: > 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 > > -- SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper http://www.sqlalchemy.org/ To post example code, please provide an MCVE: Minimal, Complete, and Verifiable Example. See http://stackoverflow.com/help/mcve for a full description. --- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/sqlalchemy/d708f89a-c84d-4d32-87f5-a70d44419fd0n%40googlegroups.com.
