ran ur tutorial on adding information to databases and querying against a virtual db (sqlite in memory)
im using the driver of pymysql version 0.4 (i know its kinda old, but when was using newer version i had other bugs, not related to this topic).
import sqlalchemy
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from CpuTable import CpuTable
def read_from_DB():
engine = create_engine('mysql+pymysql://***@***/test', echo=True)
Session = sessionmaker(bind=engine)
session=Session()
# insert = CpuTable(id='15',name= 'igal')
# session.add(insert)
# session.commit()
print()
print(str(session.query(CpuTable.id.label('id')).all()))
for cpu_id,cpu_name in session.query(CpuTable).all():
print(cpu_id,cpu_name)
C:\Python33\python.exe J:/working_dir/TLM/lib/DB_Wrapper/Lab_DB/DB_Reader.py
2014-02-12 11:23:57,193 INFO sqlalchemy.engine.base.Engine SELECT DATABASE()
2014-02-12 11:23:57,193 INFO sqlalchemy.engine.base.Engine ()
2014-02-12 11:23:57,196 INFO sqlalchemy.engine.base.Engine SHOW VARIABLES LIKE 'character_set%%'
2014-02-12 11:23:57,196 INFO sqlalchemy.engine.base.Engine ()
2014-02-12 11:23:57,198 INFO sqlalchemy.engine.base.Engine SHOW VARIABLES LIKE 'sql_mode'
2014-02-12 11:23:57,198 INFO sqlalchemy.engine.base.Engine ()
2014-02-12 11:23:57,199 INFO sqlalchemy.engine.base.Engine BEGIN (implicit)
2014-02-12 11:23:57,199 INFO sqlalchemy.engine.base.Engine SELECT
cpu.id AS id
FROM cpu
2014-02-12 11:23:57,199 INFO sqlalchemy.engine.base.Engine ()
Traceback (most recent call last):
File "C:\Python33\lib\site-packages\sqlalchemy-0.9.0-py3.3.egg\sqlalchemy\engine\result.py", line 69, in __getitem__
KeyError: <sqlalchemy.sql.elements.Label object at 0x0000000003C6FDA0>
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "J:/working_dir/TLM/lib/DB_Wrapper/Lab_DB/DB_Reader.py", line 39, in <module>
read_from_DB()
File "J:/working_dir/TLM/lib/DB_Wrapper/Lab_DB/DB_Reader.py", line 26, in read_from_DB
print(str(session.query(CpuTable.id.label('id')).all()))
File "C:\Python33\lib\site-packages\sqlalchemy-0.9.0-py3.3.egg\sqlalchemy\orm\query.py", line 2264, in all
File "C:\Python33\lib\site-packages\sqlalchemy-0.9.0-py3.3.egg\sqlalchemy\orm\loading.py", line 75, in instances
File "C:\Python33\lib\site-packages\sqlalchemy-0.9.0-py3.3.egg\sqlalchemy\orm\loading.py", line 75, in <listcomp>
File "C:\Python33\lib\site-packages\sqlalchemy-0.9.0-py3.3.egg\sqlalchemy\orm\loading.py", line 74, in <listcomp>
File "C:\Python33\lib\site-packages\sqlalchemy-0.9.0-py3.3.egg\sqlalchemy\orm\query.py", line 3440, in proc
File "C:\Python33\lib\site-packages\sqlalchemy-0.9.0-py3.3.egg\sqlalchemy\engine\result.py", line 71, in __getitem__
File "C:\Python33\lib\site-packages\sqlalchemy-0.9.0-py3.3.egg\sqlalchemy\engine\result.py", line 317, in _key_fallback
sqlalchemy.exc.NoSuchColumnError: "Could not locate column in row for column '
cpu.id'"
hence my question is what can be the problem when working against mysql db with pymysql driver?
tried searching the web for 1 day for similar problems couldnt find even 1. my sqlalchemy version was 0.9.1 and i downgraded it to 0.9 and still the problem persists.