Google App Engine – Fix an error when adding another property to datastore (webapp2)

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.

Advertisements

2 thoughts on “Google App Engine – Fix an error when adding another property to datastore (webapp2)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s