when i access the name column it give me error
AttributeError: Could not locate column in row for column 'name'
however when i print category it is printed, because it exists in db but can't get column attribute.
parent_id = 29
with Session(e) as session:
category = session.execute(select(Category).where(Category.wp_id == parent_id)).first()
print(category[0].name)
cat[0].child_categories.append(keyword)
session.add(cat)
session.commit()
model:
class Category(Base):
__tablename__ = "category"
id = Column(Integer, primary_key=True)
wp_id = Column(Integer, nullable=False, unique=True)
name = Column(String)
child_categories = relationship("Keyword", back_populates="parent_category", cascade="all, delete-orphan")
note: this is pure sqlalchemy
edit
>>> from db.operations import add_keyword_to_db
>>> add_keyword_to_db(29, 'dota 2', 30)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "E:\Projects\ongoing_projects\wp_auto\db\operations.py", line 62, in add_keyword_to_db
print(cat.name)
AttributeError: Could not locate column in row for column 'name`
this is the function that prints the name,
def add_keyword_to_db(parent_id: int, keyword_name: str, keyword_wp_id) -> None:
global engine
with Session(engine) as session:
cat = session.execute(select(Category).where(Category.wp_id == parent_id)).first()
print(cat.name)
# keyword = Keyword(name=keyword_name, wp_id=keyword_wp_id)
# cat.child_categories.append(keyword)
# session.add(cat)
# session.commit()