今天剛好玩到資料存放區 API 這個地方,結果在測試程式碼 5-1 時,出現了錯誤訊息。原始碼如下:
from google.appengine.ext import db class User(db.Model): name = db.StringProperty(required = True) email = db.EmailProperty(required = True) created = db.DateTimeProperty(auto_now_add=True) u = User() u.name = 'Eric' u.email = 'eric@example.com' u.put() print u.created |
錯誤訊息:
BadValueError: Property email is required
結果試了好一陣子才發現,原來屬性 required 設成 True 的話,資料必須在生成時就給入初值才行:
u = User(name = 'Eric', email = 'eric@example.com')