0

I have just started using mongoengine, I referred to the tutorials given at http://docs.mongoengine.org/tutorial.html I am getting an error when I am trying to add Post data to the database

mongoengine.errors.ValidationError: ValidationError (Post.TextPost:None) (A ReferenceField only accepts DBRef, LazyReference, ObjectId or documents: ['author']

I have added the screenshots of the files.

The main app.py file and the directory structure

users.py file

posts.py file

comments.py file

1 Answers1

0

The reason that validation fails is because you are assigning the post author to be a string (e.g., post1.author = 'Pratik') whereas you should assign it to an User instance:

post1.author = User(firstname='Pratik', lastname='Tester', email='Pratik.Tester@test.it')
Roman Kutlak
  • 2,684
  • 1
  • 19
  • 24