[英]In Google App Engine, how do I create a model with a specific ID?
I have backed up all of the entities for a model in a CSV file. 我已经为CSV文件中的模型备份了所有实体。 I am recovering the entities to my local dev_server and would like to recreate the entities with an ID in the csv file (similar to how bulkloader does).
我正在将实体恢复到我的本地dev_server,并希望在csv文件中重新创建具有ID的实体(类似于bulkloader的工作方式)。 How do I pass in the desired ID for my new entity in my create statement?
如何在我的create语句中为新实体传入所需的ID?
playerID = 1234
player = Player(created = datetime.datetime(2012, 1, 25, 9, 20, 5, 757227),
nickname = u'chris',
email = u'chris@home.com')
player.put()
What do I add to Player() to create the player with player.key().id()==1234 when I call put()? 当我调用put()时,我添加到Player()以使用player.key()创建播放器.id()== 1234?
First you need to allocate the id range using allocate_id_range , to make sure to reserve the ids for those entities. 首先,您需要使用allocate_id_range分配id范围,以确保为这些实体保留ID。
And then just build the key manually, and pass it to Player
constructor: 然后手动构建密钥,并将其传递给
Player
构造函数:
k = Key.from_path('Player', playerID)
player = Player(key = k, ...)
player.put()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.