问题
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