As mentioned in my previous post, I am currently developing a simple Q&A website. I was able to display a list of questions submitted by users but I also wanted to display who wrote the post on my front page .
I simply added another property “firstName” of the user to my db model in order to indicate who submitted the question.
The original code is shown below.
class Post(db.Model): question = db.StringProperty(required = True) created = db.DateTimeProperty(auto_now_add = True) last_modified = db.DateTimeProperty(auto_now = True)
I simply copied the code “db.StringProperty(required = True)”
class Post(db.Model): question = db.StringProperty(required = True) firstName = db.StringProperty(required = True) created = db.DateTimeProperty(auto_now_add = True) last_modified = db.DateTimeProperty(auto_now = True)
The code was correct but I couldn’t figure out why I was getting an error.
After searching on the internet for a few minutes, I was able to fix the issue by removing “required = True” from the firstName property.
The app was returning an error because I already stored data to the previous datastore object without the property “firstName” and adding another property which is required would make my app search for a property that does not exist.
Because I was adding a property that did not exist before, I had to remove the “required=True” to allow the app to run without the property.
This is probably not a common issue for many programmers and it is kind of a silly mistake. However, a simple issue like this can be sometimes overlooked.
Instead of removing `required=True` you could also add something like `default=”N/A”`…
Thanks Mihail! I’ll definitely try your suggestion as it is better to provide more constraints.