I’m trying to design an application that has several engines and unique
models associated with each engine.
Ideally, I’d like to create one base/abstract model per engine, set the
bind for those, and have all child models inherit that bind. Unfortunately
I can’t seem to figure out how that would work. My best guess is the
following non-working solution:
# in models.py:
Base1 = declarative_base()
Base2 = declarative_base()
class User1(Base1):
“””
Some model assigned to engine 1
“””
class User2(Base2)
“””
Some model assigned to engine 2
“””
# in main.py:
engine1 = create_engine("postgresql+psycopg2://URI1”)
engine2 = create_engine("postgresql+psycopg2://URI2”)
from .models import Base1, Base2
mybinds = {
Base1 : engine1,
Base2 : engine2
}
db = scoped_session(sessionmaker())
db.configure(binds=mybinds)
This results in the following error:
sqlalchemy.orm.exc.UnmappedClassError: Class
'sqlalchemy.ext.declarative.api.Base' is not mapped
I’ve tried to use an abstract base as a key for mybinds with no luck,
however, when I use User1, User2, it works. I don’t want to do it like this
because I have a large number of models and would prefer not to list them
all out in the binds dictionary.
How do I assign a bind to a model in this case?
Thanks!
--
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 post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.