我正在尝试将一条记录插入到远程数据库的mysql表中。python可以工作(没有错误),但我的插入都没有反映在远程数据库中。SQLAlchemy似乎维护了一个缓存,并且正在更新它,而不是推送它。我甚至把表放在服务器上,SQLAlchemy仍然认为它是存在的。
我不使用Session或以其他方式提交事务,尽管当我回显语句时,似乎正在发生提交。
SQLAlchemy是否维护某种缓存?
from sqlalchemy import MetaData
from sqlalchemy import Table
from sqlalchemy import create_engine
db_engine2 = create_engine('mysql+mysqldb://user:pass@host/product_analytics', echo=True)
meta = MetaData(db_engine2)
xlations_topic_update_status = Table('product_analytics.xlations_topic_update_status', meta, autoload=True)
xlations_topic_update_status.insert().execute({'topic_name':'test','topic_id':'test2'}, autocommit=True)
print(xlations_topic_update_status.select().execute().fetchall())下面是我在把表放在服务器上之后所看到的:

发布于 2019-01-31 20:57:58
弄明白了..。
"product_analytics.xlations_topic_update_status". Table('product_analytics.xlations_topic_update_status', meta, autoload=True)在product_analytics数据库中默默地创建了一个表而不是使用"xlations_topic_update_status“表
经验教训:不包括数据库名称。
https://stackoverflow.com/questions/54463277
复制相似问题