代码之家  ›  专栏  ›  技术社区  ›  steve

如何在谷歌云数据存储中创建新模型(种类)

  •  3
  • steve  · 技术社区  · 8 年前

    我正在为我的项目使用谷歌云数据存储(不是NDB)。

    我想创建一个新模型,比如说标签模型。

    class Tag(db.Model):
        name = ndb.StringProperty()
        feature = ndb.StringProperty(default='')
    

    我已经多次向模型添加属性,但尚未创建新模型。

    提前感谢!

    2 回复  |  直到 8 年前
        1
  •  5
  •   Dan McGrath    8 年前

    与MySQL等SQL数据库不同,云数据存储不需要提前创建种类(类似于表)。除了在代码中定义它之外,创建这种类型不需要任何管理步骤。

    当您编写第一个此类实体时,它是为您隐式创建的。

    您甚至可以查询尚不存在的种类,但不会出错,只会返回任何实体:

    Example GQL statement on a kind that doesn't exist, shows message of "No entities matched this query"

        2
  •  0
  •   Mauricio Cortazar    8 年前