我正在尝试将数据导入现有数据库项。我想为每个数据库项更新两个字段:一个字符串类型字段caled imagefolder
和一个名为images
的picketype(list)字段。两个字段的输入值都是存储文件路径的字符串。在
我的步骤是查询数据库项,检查其存在性,然后更新其字段。在
blend = Blend.query.filter_by(old_ID=row[4]).first()
if blend:
blend.imagefolder = "/".join((row[16].split("/")[4:])[:-1])
blend.images.append(ntpath.basename(row[16]))
db.session.commit()
当我运行脚本时,什么都没有发生(数据库没有更新),我注意到导入脚本运行得非常快,太快了。在
未能将更改的对象添加到当前会话。在
试试下面的片段。在
相关问题 更多 >
编程相关推荐