问题
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.
回答1:
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
来源:https://stackoverflow.com/questions/6273688/how-to-upload-data-with-key-name-by-google-app-engine-bulkloader