【问题标题】:How to upload data with key_name by Google App Engine bulkloader如何通过 Google App Engine bulkloader 上传带有 key_name 的数据
【发布时间】:2011-06-08 02:48:49
【问题描述】:

我可以上传数据,但 key_name 为空。 如何使用 CSV 中的“id”作为数据存储区的 key_name?

我喜欢使用 'id' 作为 key_name,因为其他数据使用 'id' 作为外键。 我是 Google App Engine 的新手。

这是 CSV 数据。

"id","name"
"1","USA"
"2","France"
"3","Italy"

这是YAML

- model: model.testcountry.TestCountry
  connector: csv
  connector_options:
    encoding: utf-8
    columns: from_header
  property_map:
    - property: __key__
      external_name: id
    - property: name
      external_name: name

P.S:我正在尝试将数据上传到本地环境。


更新

感谢您的帮助,我尝试了代码,但效果不佳。 结果很奇怪。

在终端窗口中,一条日志消息告诉我上传成功完成, 但是我在 Google App Engine 控制台 (http://localhost:8080/_ah/admin/datastore) 中找不到任何记录。数据存储为空,没有记录。

终端窗口中的日志信息是这样的

输入命令

appcfg.py upload_data --config_file=bulkloader.yaml --filename=testcountries.csv --kind=TestCountry --url=http://localhost:8080/remote_api --num_thread=1 

结果信息

Uploading data records.
[INFO    ] Logging to bulkloader/log.log
[INFO    ] Throttling transfers:
[INFO    ] Bandwidth: 250000 bytes/second
[INFO    ] HTTP connections: 8/second
[INFO    ] Entities inserted/fetched/modified: 20/second
[INFO    ] Batch Size: 10
Please enter login credentials for localhost:8080
Email: xxxxxxx
Password for l: 
[INFO    ] Opening database: bulkloader-progress-20110609.003032.sql3
[INFO    ] Connecting to localhost:8080/remote_api
[INFO    ] Starting import; maximum 10 entities per post
..........
[INFO    ] 100 entities total, 0 previously transferred
[INFO    ] 100 entities (3362 bytes) transferred in 1.9 seconds
[INFO    ] All entities successfully transferred

我也试过这个,但结果是一样的。终端显示成功,但在 Google App Engine 控制台中没有记录......

import_transform: int

PS:我使用的是 Mac OS X Snow Leopard 和 Google App Engine 启动器。

【问题讨论】:

    标签: python google-app-engine bulkloader


    【解决方案1】:

    试试这个:

    - import: google.appengine.ext.bulkload.transform
    - model: model.testcountry.TestCountry
      connector: csv
      connector_options:
        encoding: utf-8
        columns: from_header
        property_map:
        - property: __key__
          external_name: id
          import_transform: transform.create_foreign_key('TestCountry')
        - property: name
          external_name: name
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-20
      • 1970-01-01
      • 2010-12-13
      • 1970-01-01
      相关资源
      最近更新 更多