I have a table mailtable in a backend PostgreSQL database and I'm querying it using SQLAlchemy ORM using a given mailId. For the following code, the amEngine is already set up. When it gets to the mailRow.usercomment = 'Hello World' line, it throws:
AttributeError: can't set attribute
Base = declarative_base()
Base.metadata.reflect(amEngine)
metaAm = MetaData()
metaAm.reflect(bind=amEngine)
mt = metaAm.tables['mailtable']
Session = sessionmaker(bind=amEngine)
amSession = Session()
mailRow = amSession.query(
mt
).filter(
mt.c.id == mailId
).first()
mailAddress = mailRow.address
mailRow.usercomment = 'Hello World'
amSession.flush()
amSession.commit()
I need to read the address column (successful) and update the usercomment column (throws exception). The PostgreSQL type for both columns is text.
How can I do this? I'm sure this must be a very simple issue, but for the life of me I cannot see the problem.
Many thanks.