Dr. John A Zoidberg
Dr. John A Zoidberg

Reputation: 1248

Why does this not update my table in sqlalchemy?

I have the following code:

engine = sqlalchemy.create_engine(connectstring, echo=_echo).connect()
md = sqlalchemy.MetaData(engine)
table = sqlalchemy.Table('table_name', md, autoload=True, autoload_with=engine)
_Session = sessionmaker(bind=engine)
session = _Session()

for row in reader:
    table.insert({'key': 'value'})
session.commit()

Why does nothing get added to my table? The code runs, but the table is never updated.

Upvotes: 0

Views: 64

Answers (1)

Dr. John A Zoidberg
Dr. John A Zoidberg

Reputation: 1248

the insertion was never executed.

table.insert({'key': 'value'}).execute()

fixes this problem.

Upvotes: 1

Related Questions