首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > perl python >

大神一个python中使用SQLalchemy模块的有关问题

2013-02-15 
请教各位大神一个python中使用SQLalchemy模块的问题python中用sqlalchemy模块连接数据库表建立mapping关系

请教各位大神一个python中使用SQLalchemy模块的问题
python中用sqlalchemy模块连接数据库表建立mapping关系后

test_record = test_session.query(test_attachment).filter(test_attachment._id == '56').all()[0]
print test_record
test_record._fileName = 'testfile'

test_session.update(test_record) #操作失败。。。
                                 #??对象修改后,除了用update语句
                                 #??怎么更新数据到数据库。。。
test_session.commit()
python
[解决办法]
如果_id是主键的话,直接test_session.query(test_attachment).filter(test_attachment._id == '56').first()就可以
你要修改_fileName的值为'testfile',之后直接commit就行
我的做法是这样的:
找到要修改的: rs = db.session.query('XXX').filter_by(_id=xxxx).first()
修改内容: rs._fileName='testfile'
提交修改: db.session.commit()

热点排行