我们有一个带有JSON字段的模型,用户标志插入其中.插入确实按预期工作,但是当删除某些标志时,它们会保留在字段中,并且更改不会持久保存到数据库.
我们的模型中有以下方法:
def del_flag(self, key):
if self.user_flags is None or not key in self.user_flags:
return False
else:
del self.user_flags[key]
db.session.commit()
return True
Run Code Online (Sandbox Code Playgroud)
数据库是postgres,我们使用SQLalchemy JSON字段方言作为字段类型.有什么建议吗?