Category : sqlalchemy

The following snippet of code described below is working fine on Windows, but on Ubuntu , the postgres data base is getting connected, but unable to dump a python dataframe into database table. Moreover if i only import sqlalchemy and doesnt write the code which is displayed after Line-8 then it doesnt display the error ..

Read more

Using SQLAlchemy I have three models: Parent1, Parent2, and Child, where Parent1 has one-to-one relationship with Parent2, and both of them has the same relationship with Child. Here are they: from extensions import db_session class Parent1(Base): __tablename__ = ‘parent1’ id = Column(Integer, primary_key=True) name = Column(String, nullable=False) parent2 = relationship("Parent2", backref="parent1", uselist=False) child = relationship("Child", ..

Read more

Using Python 3.6, SQLAlchemy 1.4 ASYNC engine with Postgres backend. The beginning of the database class: class Db: def __init__(self, config): self._engine = create_async_engine(‘postgresql+asyncpg://[email protected]:5432/db’, echo=True, future=True) self._session = sessionmaker(self._engine, expire_on_commit=False, class_=AsyncSession) self._meta = MetaData() self._cache = self.cache() @property def meta(self): self._meta.reflect(bind=sync_engine) return self._meta @property def cache(self): Base = automap_base() Base.prepare(sync_engine, reflect=True) return Base I am ..

Read more

So I have these two simple classes inside the same python file which I’m trying to map with SQLAlchemy, where User column ‘password_id’ is a foreign key to the table Password ‘password_id’ column as well from sqlalchemy.orm import relationship, declarative_base from sqlalchemy import Column, Integer, String from sqlalchemy.sql.schema import ForeignKey Base = declarative_base() class User(Base): ..

Read more