Posts

Showing posts with the label sqlalchemy

How do I split an SQLAlchemy Declarative model into modules?

How do I split an SQLAlchemy Declarative model into modules? I need to define multiple modules that contain SQLAlchemy Declarative classes. I've written a function in each module called subclass_base() into which a Base instance of declarative_base() is passed after instantiation. The first module's subclass_base() call correctly subclasses the Base instance and the subclasses are visible from outside the function. The second module's call finishes without errors but from both within the function and outside of it all of the subclasses are reflected in Base.__subclasses__ only some of the time. Here is a minimal working example with only 1 class definition in each module: subclass_base() declarative_base() subclass_base() Base.__subclasses__ modela.py from sqlalchemy import Column, Integer, String def subclass_base(Base): class Roles(Base): __tablename__ = 'roles' id = Column(Integer, primary_key=True) name = Column(String(32)) modelb...

insert to Db2 using Flask and sqlalchemy

insert to Db2 using Flask and sqlalchemy I have a Flask application with sqlalchemy in it. Running manage db init , manage db migrate and manage db upgrade worked perfectly. So the tables are created on db2 without any problems. When i try to do an insert, i get all kinds of errors. manage db init manage db migrate manage db upgrade Traceback (most recent call last): File "*path*/lib/python3.6/site-packages/ibm_db_dbi.py", line 1258, in _execute_helper return_value = ibm_db.execute(self.stmt_handler, parameters) Exception: Binding Error: During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/Users/sebastianlindblom/Documents/GrowSmarter/metrolive-api-env/lib/python3.6/site-packages/sqlalchemy/engine/base.py", line 1193, in _execute_context context) File "/Users/sebastianlindblom/Documents/GrowSmarter/metrolive-api-env/lib/python3.6/site-packages/ibm_db_sa/ibm_db.py", line 107, in do_ex...