MongoEngine - Deleted field still raises ValidationError

眉间皱痕 提交于 2019-12-12 04:32:14

问题


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.

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?


回答1:


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.



来源:https://stackoverflow.com/questions/11841034/mongoengine-deleted-field-still-raises-validationerror

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!