在 Google App Engine 中,如何创建具有特定 ID 的模型?
我已将模型的所有实体备份到 CSV 文件中。我正在将实体恢复到本地 dev_server,并希望使用 csv 文件中的 ID 重新创建实体(类似于bulkloader 的做法)。如何在创建语句中传递新实体所需的 ID?
playerID = 1234
player = Player(created = datetime.datetime(2012, 1, 25, 9, 20, 5, 757227),
nickname = u'chris',
email = u'[email protected]')
player.put()
当我调用 put() 时,我应该向 Player() 添加什么来创建带有player.key().id()==1234 的播放器?
I have backed up all of the entities for a model in a CSV file. 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). How do I pass in the desired ID for my new entity in my create statement?
playerID = 1234
player = Player(created = datetime.datetime(2012, 1, 25, 9, 20, 5, 757227),
nickname = u'chris',
email = u'[email protected]')
player.put()
What do I add to Player() to create the player with player.key().id()==1234 when I call put()?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,您需要使用 allocate_id_range 分配 ID 范围,以确保保留 ID对于那些实体。
然后手动构建密钥,并将其传递给
Player
构造函数:First you need to allocate the id range using allocate_id_range, to make sure to reserve the ids for those entities.
And then just build the key manually, and pass it to
Player
constructor: