I am trying to run the following simple operation to update entries of a SQL Table with sqlite:
from sqlalchemy import create_engine
from sqlalchemy import Column, String
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker
from sqlalchemy import update
engine = create_engine("sqlite:///tests.db", echo=True)
session = sessionmaker(bind=engine)()
Base = declarative_base()
class User(Base):
__tablename__ = "usertable"
username = Column(String, primary_key=True)
password = Column(String)
Base.metadata.create_all(engine)
user = User()
user.username = "John"
user.password = "pass"
session.add(user)
session.commit()
stmt = update(User).where(User.c.password == 'pass').values(password='PASSWORD')
session.execute(stmt)
session.commit()
But when I run this I get the following error:
AttributeError: 'User' object has no attribute 'c'
Can someone please clarify the right way to do this?
User.c
?.c
. The relevant tutorial docs are here.