删除数据报warning
来源:5-2 flask入门
qq_天下无敌_3
2018-06-29
/usr/local/lib/python2.7/dist-packages/sqlalchemy/orm/persistence.py:1066: SAWarning: DELETE statement on table 'scopeofworkanswerindex' expected to delete 1 row(s); 3 were matched. Please set confirm_deleted_rows=False within the mapper configuration to prevent this warning.
(table.description, expected, rows_matched)
code:
data = session.query(model.scopeofworkanswerindex.Sindex).get(11504)
if data:
session.delete(data)
session.commit()
Base = declarative_base()
class Svalue(Base):
__tablename__ = 'scopeofworkanswervalue'
id = Column(Integer, primary_key=True)
__mapper_args__ = {
'confirm_deleted_rows': False
}
请问这样设置不对吗 应该怎么设置呢
2回答
-
NavCat
2018-06-29
补充一点,在数据库,或者表命名时,可以添加下划线分割,譬如你的表名为scopeofworkanswervalue,要考虑代码的可维护性和可阅读性,可以写成这样scope_of_work_answer_value,这样会不会好一些?
00 -
NavCat
2018-06-29
你这个警告是说期望删除1条数据,实际上匹配到了3条数据。代码中你需要删除的是模型Sindex中的数据,你配置的__mapper_args__ 却在模型Svalue上。(仔细检查你的代码,另外确保sqlalchemy的版本在0.94以上)
关于mapper参考文档:
http://docs.sqlalchemy.org/en/latest/orm/mapping_api.html?highlight=confirm_deleted_rows#sqlalchemy.orm.mapper.params.confirm_deleted_rows
00
Python操作三大主流数据库-MySQL+MongoDB+Redis
2024 学习 · 376 问题
相似问题