0

I'm trying to insert a row into a table of a mysql db with sql alchemy, but when I insert and go to the database check the data, I see nothing.

This is my code:

from sqlalchemy import create_engine from sqlalchemy import Table, MetaData from sqlalchemy.sql import table, column, select, update, insert from sqlalchemy.orm import sessionmaker

engine = create_engine(
      "mysql://user:password@host/schema")
connection = engine.connect()

metadata = MetaData(bind=engine)
prices = Table('historical_prices', metadata, autoload=True)
i = insert(prices)
i = i.values({
    "date": my_date, 
    "instrument": msg['instrument'],
    "open": msg['candles'][0]['openAsk'],
    "high": msg['candles'][0]['highAsk'],
    "low": msg['candles'][0]['lowAsk'],
    "close": msg['candles'][0]['closeAsk'],
    "volume": msg['candles'][0]['volume']
    })
Session = sessionmaker(bind=engine)
session = Session()
session.execute(i)

I receive no error message from this code. How can I fix this?

2
  • 2
    I don't know if it's because you've left it out, but you're missing a session.commit(). Commented Jul 28, 2017 at 3:33
  • @univerio thanks! this solved the issue. Would you like to answer the question? So I can accept it. Commented Jul 28, 2017 at 12:32

1 Answer 1

2

As the right answer haven't been posted yet by the original person who came up with it. I am going forward to do so.

I don't know if it is because You've left it out, but You're missing a session.commit()

Hopefully this answer will be more visible for next people with the same problem.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.