如何通过 Google App Engine 批量加载程序使用 key_name 上传数据

发布于 2024-11-14 02:29:23 字数 2040 浏览 3 评论 0原文

我可以上传数据,但 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

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


更新

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

在终端窗口中,日志消息告诉我上传已成功完成, 但是我在 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 启动器。

I can upload data, but key_name is empty.
How can I use the 'id' in the CSV as the key_name on datastore?

I'like to use 'id' as the key_name, because other data uses the 'id' as the foreign key.
I'm new to Google App Engine.

This is the CSV data.

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

This is the 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: I'm trying upload data to the local enviroment.


Update

Thank you for the help, I tried the code, but it does not work well.
The result is strange.

In the terminal window a log message tells me that uploading finished successfully,
however I cannot find any records in the Google App Engine console (http://localhost:8080/_ah/admin/datastore). The datastore is empty, there is no record.

The log message in the terminal window is this

Entering command

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

Result message

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

I also tried this, but result was same. The terminal says success but in the Google App Engine console there are no records....

import_transform: int

PS: I'm using Mac OS X Snow Leopard and Google App Engine launcher.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

尐偏执 2024-11-21 02:29:23

试试这个:

- 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

Try this:

- 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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文