如何从db.model迁移到ndb.model?

时间:2017-01-28 16:31:01

标签: google-app-engine google-cloud-datastore app-engine-ndb gae-python27

我有一个使用db.model的旧gae应用。我知道我应该迁移到ndb.model。有简单的方法还是我必须做出很多改变?

我的代码相当大,我有一个用于构建索引和搜索的旧模型db.model。我应该保留旧模型并制作新的ndb模型还是尝试更改旧模型?

模型中的一些变量是

cities = db.ListProperty(db.Key) #ndb.KeyProperty(repeated=True)
regions = db.ListProperty(db.Key) #ndb.KeyProperty(repeated=True)
blobs = db.ListProperty(db.BlobKey)  #ndb.BlobProperty(repeated=True)
primary_image = blobstore.BlobReferenceProperty()
usr = db.ReferenceProperty()  # ndb_model.KeyProperty()
hasimages = db.BooleanProperty(default=False,
                               verbose_name='has_images')
userID = db.StringProperty(verbose_name='User ID')
integer_price = db.IntegerProperty()
ip = ndb.StringProperty(verbose_name='ip')
ipcountry = db.StringProperty(indexed=False, verbose_name='origin')
tags = db.ListProperty(db.Category)
category = db.CategoryProperty(verbose_name='Category')
title = db.StringProperty(verbose_name='title')  # required
user = db.UserProperty(verbose_name='userid')
im = db.IMProperty(verbose_name='nickname')  # optional, xmpp
city = db.StringProperty()  # postaladdress should work instead
region = db.StringProperty()  # postaladdress should work instead
url = db.StringProperty(verbose_name='url')
geopt = db.GeoPtProperty(verbose_name='geopt')
text = db.TextProperty(verbose_name='text')

1 个答案:

答案 0 :(得分:1)

它不应该特别复杂,并且可以逐步完成,因为您可以在同一个二进制文件中混合使用db和ndb代码。请参阅DB to NDB Client Library Migration