当我尝试使用带有 SQLAlchemy 的会话执行添加时,我目前遇到以下错误。
sqlalchemy.exc.ProgrammingError: (ProgrammingError) (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '%s)' at line 1") b'INSERT INTO ctr_status (`Name`) VALUES (%s)' ('Test',)
这是代码:
from sqlalchemy import MetaData, Table
from sqlalchemy import create_engine, orm
# Login omitted...
url = 'mysql+mysqldb://{user}:{password}@{host}:{port}/{database}'.format(user=user, password=password, host=host, port=port, database=database)
e = create_engine(url, echo=True)
metadata = MetaData()
metadata.bind = e
metadata.create_all()
ctr_status = Table('ctr_status', metadata, autoload=True)
class CTRStatus(object):
pass
orm.mapper(CTRStatus, ctr_status)
new_status = CTRStatus()
new_status.Name = 'Test'
session_maker = orm.sessionmaker(bind=e, autoflush=True, autocommit=False, expire_on_commit=True)
session = orm.scoped_session(session_maker)
session.add(new_status)
# Crash here at flush
session.flush()
我对自己做错了什么感到困惑。我目前正在使用MySQL 5.5、Python 3.3.2和SQLAlchemy-0.8.2.win32-py3.3。
以下是我一直关注的一些链接: