根据AppEngine documentation (下面引用),使用 download_data 和 upload_data 应该保留下载数据的原始 key 。
When data is downloaded, the entities are stored along with their original keys. When the data is uploaded, the original keys are used. If an entity exists in the datastore with the same key as an entity being uploaded, the entity in the datastore is replaced.
我正在使用这两个命令:
appcfg.py download_data --oauth2 --url=https://myapp-id.appspot.com/_ah/remote_api --filename=testdata/gamedata
appcfg.py upload_data --url=http://localhost:9876/_ah/remote_api --filename=testdata/gamedata
数据上传的 ID 相同,但 key 不同,知道我做错了什么吗?或者 key 的计算方式是否与本地 devappserver 不同?
更新
添加一些数据来比较产品版本和本地开发版本
生产 key :ag9zfmF3ZXNvbWVzdGdhbWVyGAsSCENhdGVnb3J5IgrYo9is2YbYqNmKDA
从 PROD 中下载数据并将数据上传到本地主机后, key 变为同一对象:ahFkZXZ-YXdlc29tZXN0Z2FtZXIYCxIIQ2F0ZWdvcnkiCtij2KzZhtio2YoM
最佳答案
您需要在批量加载器配置中使用适当的转换,例如,如果您使用 ids,则类似
- kind: YourEntity
connector: csv
property_map:
- property: __key__
external_name: key
export_transform: transform.key_id_or_name_as_string
import_transform: transform.none_if_empty(transform.create_foreign_key('YourEntity', key_is_id=True))
- property: more props...
会在进入和退出时转换按键。
如果你的实体有 parent ,那么你需要在出去时 split 并在进来时重新组合:
- kind: ChildEntity
connector: csv
property_map:
- property: __key__
external_name: childKey
import_transform: transform.create_deep_key(('ParentEntity', 'parentKey', True),('ChildEntity', transform.CURRENT_PROPERTY, True))
export:
- external_name: parentKey
export_transform: transform.key_id_or_name_as_string_n(0)
- external_name: childKey
export_transform: transform.key_id_or_name_as_string_n(1)
关于google-app-engine - AppEngine 中 download_data 和 upload_data 键的差异,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17267299/