MongoEngine-删除的字段仍会引发ValidationError [英] MongoEngine - Deleted field still raises ValidationError

查看:234
本文介绍了MongoEngine-删除的字段仍会引发ValidationError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将Flask与MongoEngine一起使用,并且作为测试,我尝试通过创建一个Python文件来向MongoEngine添加一个集合,该集合在其模式中具有一些必填字段,该文件包含一个子类,该类继承了mongoengine.Document并具有一些MongoEngine字段

I'm using Flask with MongoEngine and as a test I tried to add a collection to MongoEngine with a few required fields in its schema by creating a Python file which contains a class that subclasses mongoengine.Document and has a few MongoEngine fields in it, which worked fine.

但是后来我从架构中删除了其中一些字段(仅通过编辑子类mongoengine.Document的python类)并试图将新文档添加到集合中后,MongoEngine对我已经从架构中删除的字段抛出了ValidationErrors。有什么方法可以重置模式,又如何避免MongoEngine将来做同样的事情?

But when I later removed some of those fields from the schema (just by editing the python class which subclasses mongoengine.Document) and tried to add new documents to the collection, MongoEngine threw ValidationErrors for the fields that I had already removed from the schema. Is there a way I could reset the schemas, and how can I avoid MongoEngine from doing the same in the future?

推荐答案

有您重新启动了Flask / Web服务器,因为文档可能已缓存在模块中。通过重新启动Web服务器来重新加载模块,这些定义将不存在,并且不会引发错误-MongoEngine仅在mongoDB数据中不存储任何架构状态信息。

Have you restarted the Flask / web server as the documents are probably cached in the module. Reload the module by restarting the webserver and those definitions won't be there and it won't throw an error - MongoEngine stores no schema state information in mongoDB only data.

这篇关于MongoEngine-删除的字段仍会引发ValidationError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆