GitHub user dosubot[bot] added a comment to the discussion: 关于电网拓扑数据导入
<!-- Answer -->
你遇到的“Make sure the primary key fields [id] are not empty, or check whether the
headers or field_mapping are configured correctly”报错,根本原因是 struct_1.json 的
edges 配置 field_mapping 写成了 `"from": "id", "to": "id"`,而不是 `"from": "from",
"to": "to"`,或者 source/target 配置写反了,或者 CSV header/数据有问题。
**请严格检查以下几点:**
1. struct_1.json 的 edges 配置必须是:
```json
"source": ["from"],
"target": ["to"],
"field_mapping": { "from": "from", "to": "to" }
```
不能有 id,不能写反 source/target。
2. power_edges_to.csv(或 edge_connected_to.csv)header 必须严格为:
```
id,from,to,label,source_label,target_label
```
没有多余空格、没有 BOM、没有隐藏字符。
3. 所有 from/to 字段都不能有空值,且和顶点 id 完全一致(无多余空格、无大小写问题、无空行)。
4. struct_1.json 的 null_values 建议只保留 ["NULL", "null"],不要加 "",否则空字符串会被判定为
null,导致 id 为空。
5. schema.groovy 的边标签 .properties() 只包含实际需要的属性(如 "source_label",
"target_label"),不要加 "id"。
**常见坑:**
- source/target 写反(比如 "source": ["to"], "target": ["from"])
- field_mapping 写成了 id
- CSV header 有隐藏字符或 BOM
- null_values 配置了空字符串
- 顶点 id 有重复或空行
**如果你已经全部按上述做了,还是报错,请贴出:**
- power_edges_to.csv 的 header 和前 2 行原始数据(不要做任何处理)
- struct_1.json 某个 edges 配置的完整内容(尤其是 source/target/field_mapping/value_mapping)
这样我可以帮你定位具体是哪一行或哪一列有问题。
只要这些全部做到,边就能正常导入且无报错,所有关系都能导入。[官方FAQ说明](https://github.com/apache/incubator-hugegraph-doc/blob/master/content/en/docs/guides/faq.md)
<!-- Dosu Comment Footer -->
*To reply, just mention [@dosu](https://go.dosu.dev/dosubot).*
---
<sup>How did I do?
[Good](https://app.dosu.dev/response-feedback/382f0552-e460-43fe-8327-0223fc1f9af0?feedback_type=great_response)
|
[Irrelevant](https://app.dosu.dev/response-feedback/382f0552-e460-43fe-8327-0223fc1f9af0?feedback_type=irrelevant_answer)
|
[Incorrect](https://app.dosu.dev/response-feedback/382f0552-e460-43fe-8327-0223fc1f9af0?feedback_type=incorrect_sources)
|
[Verbose](https://app.dosu.dev/response-feedback/382f0552-e460-43fe-8327-0223fc1f9af0?feedback_type=too_verbose)
|
[Hallucination](https://app.dosu.dev/response-feedback/382f0552-e460-43fe-8327-0223fc1f9af0?feedback_type=hallucination)
| [Report
🐛](https://app.dosu.dev/response-feedback/382f0552-e460-43fe-8327-0223fc1f9af0?feedback_type=bug_report)
|
[Other](https://app.dosu.dev/response-feedback/382f0552-e460-43fe-8327-0223fc1f9af0?feedback_type=other)</sup>
[](https://app.dosu.dev/e5e246fa-a522-4d8a-ab3c-e2588b5b501b/ask?utm_source=github) [](https://cursor.com/link/prompt?text=%E4%BD%A0%E9%81%87%E5%88%B0%E7%9A%84%E2%80%9CMake%20sure%20the%20primary%20key%20fields%20%5Bid%5D%20are%20not%20empty%2C%20or%20check%20whether%20the%20headers%20or%20field_mapping%20are%20configured%20correctly%E2%80%9D%E6%8A%A5%E9%94%99%EF%BC%8C%E6%A0%B9%E6%9C%AC%E5%8E%9F%E5%9B%A0%E6%98%AF%20struct_1.json%20%E7%9A%84%20edges%20%E9%85%8D%E7%BD%AE%20field_mapping%20%E5%86%99%E6%88%90%E4%BA%86%20%60%22from%22%3A%20%22id%22%2C%20%22to%22%3A%20%22id%22%60%EF%BC%8C%E8%80%8C%E4%B8%8D%E6%98%AF%20%60%22from%22%3A%20%22from%22%2C%20%22to%22%3A%20%22to%22%60%EF%BC%8C%E6%88%96%E8%80%85%20source/target%20%E9%85%8D%E7%BD%AE%E5%86%99%E5%8F%8D%E4%BA%86%EF%BC%8C%E6%88%96%E8%80%85%20CSV%20header/%E6%95%B0%E6%8D%AE%E6%9C%89%E9%97%AE%E9%A2%98%E3%80%82%0A%0A%2A%2A%E8%A
F%B7%E4%B8%A5%E6%A0%BC%E6%A3%80%E6%9F%A5%E4%BB%A5%E4%B8%8B%E5%87%A0%E7%82%B9%EF%BC%9A%2A%2A%0A%0A1.%20struct_1.json%20%E7%9A%84%20edges%20%E9%85%8D%E7%BD%AE%E5%BF%85%E9%A1%BB%E6%98%AF%EF%BC%9A%0A%20%20%20%60%60%60json%0A%20%20%20%22source%22%3A%20%5B%22from%22%5D%2C%0A%20%20%20%22target%22%3A%20%5B%22to%22%5D%2C%0A%20%20%20%22field_mapping%22%3A%20%7B%20%22from%22%3A%20%22from%22%2C%20%22to%22%3A%20%22to%22%20%7D%0A%20%20%20%60%60%60%0A%20%20%20%E4%B8%8D%E8%83%BD%E6%9C%89%20id%EF%BC%8C%E4%B8%8D%E8%83%BD%E5%86%99%E5%8F%8D%20source/target%E3%80%82%0A%0A2.%20power_edges_to.csv%EF%BC%88%E6%88%96%20edge_connected_to.csv%EF%BC%89header%20%E5%BF%85%E9%A1%BB%E4%B8%A5%E6%A0%BC%E4%B8%BA%EF%BC%9A%0A%20%20%20%60%60%60%0A%20%20%20id%2Cfrom%2Cto%2Clabel%2Csource_label%2Ctarget_label%0A%20%20%20%60%60%60%0A%20%20%20%E6%B2%A1%E6%9C%89%E5%A4%9A%E4%BD%99%E7%A9%BA%E6%A0%BC%E3%80%81%E6%B2%A1%E6%9C%89%20BOM%E3%80%81%E6%B2%A1%E6%9C%89%E9%9A%90%E8%97%8F%E5%AD%97%E7%AC%A6%E3%80%82%0A%0A3.%20%E6%89%80%E6%9C
%89%20from/to%20%E5%AD%97%E6%AE%B5%E9%83%BD%E4%B8%8D%E8%83%BD%E6%9C%89%E7%A9%BA%E5%80%BC%EF%BC%8C%E4%B8%94%E5%92%8C%E9%A1%B6%E7%82%B9%20id%20%E5%AE%8C%E5%85%A8%E4%B8%80%E8%87%B4%EF%BC%88%E6%97%A0%E5%A4%9A%E4%BD%99%E7%A9%BA%E6%A0%BC%E3%80%81%E6%97%A0%E5%A4%A7%E5%B0%8F%E5%86%99%E9%97%AE%E9%A2%98%E3%80%81%E6%97%A0%E7%A9%BA%E8%A1%8C%EF%BC%89%E3%80%82%0A%0A4.%20struct_1.json%20%E7%9A%84%20null_values%20%E5%BB%BA%E8%AE%AE%E5%8F%AA%E4%BF%9D%E7%95%99%20%5B%22NULL%22%2C%20%22null%22%5D%EF%BC%8C%E4%B8%8D%E8%A6%81%E5%8A%A0%20%22%22%EF%BC%8C%E5%90%A6%E5%88%99%E7%A9%BA%E5%AD%97%E7%AC%A6%E4%B8%B2%E4%BC%9A%E8%A2%AB%E5%88%A4%E5%AE%9A%E4%B8%BA%20null%EF%BC%8C%E5%AF%BC%E8%87%B4%20id%20%E4%B8%BA%E7%A9%BA%E3%80%82%0A%0A5.%20schema.groovy%20%E7%9A%84%E8%BE%B9%E6%A0%87%E7%AD%BE%20.properties%28%29%20%E5%8F%AA%E5%8C%85%E5%90%AB%E5%AE%9E%E9%99%85%E9%9C%80%E8%A6%81%E7%9A%84%E5%B1%9E%E6%80%A7%EF%BC%88%E5%A6%82%20%22source_label%22%2C%20%22target_label%22%EF%BC%89%EF%BC%8C%E4%B8%8D%E8%A6%81%E5%8A%A0%20%22id%2
2%E3%80%82%0A%0A%2A%2A%E5%B8%B8%E8%A7%81%E5%9D%91%EF%BC%9A%2A%2A%0A-%20source/target%20%E5%86%99%E5%8F%8D%EF%BC%88%E6%AF%94%E5%A6%82%20%22source%22%3A%20%5B%22to%22%5D%2C%20%22target%22%3A%20%5B%22from%22%5D%EF%BC%89%0A-%20field_mapping%20%E5%86%99%E6%88%90%E4%BA%86%20id%0A-%20CSV%20header%20%E6%9C%89%E9%9A%90%E8%97%8F%E5%AD%97%E7%AC%A6%E6%88%96%20BOM%0A-%20null_values%20%E9%85%8D%E7%BD%AE%E4%BA%86%E7%A9%BA%E5%AD%97%E7%AC%A6%E4%B8%B2%0A-%20%E9%A1%B6%E7%82%B9%20id%20%E6%9C%89%E9%87%8D%E5%A4%8D%E6%88%96%E7%A9%BA%E8%A1%8C%0A%0A%2A%2A%E5%A6%82%E6%9E%9C%E4%BD%A0%E5%B7%B2%E7%BB%8F%E5%85%A8%E9%83%A8%E6%8C%89%E4%B8%8A%E8%BF%B0%E5%81%9A%E4%BA%86%EF%BC%8C%E8%BF%98%E6%98%AF%E6%8A%A5%E9%94%99%EF%BC%8C%E8%AF%B7%E8%B4%B4%E5%87%BA%EF%BC%9A%2A%2A%0A-%20power_edges_to.csv%20%E7%9A%84%20header%20%E5%92%8C%E5%89%8D%202%20%E8%A1%8C%E5%8E%9F%E5%A7%8B%E6%95%B0%E6%8D%AE%EF%BC%88%E4%B8%8D%E8%A6%81%E5%81%9A%E4%BB%BB%E4%BD%95%E5%A4%84%E7%90%86%EF%BC%89%0A-%20struct_1.json%20%E6%9F%90%E4%B8%AA%20edges%20%E9%8
5%8D%E7%BD%AE%E7%9A%84%E5%AE%8C%E6%95%B4%E5%86%85%E5%AE%B9%EF%BC%88%E5%B0%A4%E5%85%B6%E6%98%AF%20source/target/field_mapping/value_mapping%EF%BC%89%0A%0A%E8%BF%99%E6%A0%B7%E6%88%91%E5%8F%AF%E4%BB%A5%E5%B8%AE%E4%BD%A0%E5%AE%9A%E4%BD%8D%E5%85%B7%E4%BD%93%E6%98%AF%E5%93%AA%E4%B8%80%E8%A1%8C%E6%88%96%E5%93%AA%E4%B8%80%E5%88%97%E6%9C%89%E9%97%AE%E9%A2%98%E3%80%82%0A%0A%E5%8F%AA%E8%A6%81%E8%BF%99%E4%BA%9B%E5%85%A8%E9%83%A8%E5%81%9A%E5%88%B0%EF%BC%8C%E8%BE%B9%E5%B0%B1%E8%83%BD%E6%AD%A3%E5%B8%B8%E5%AF%BC%E5%85%A5%E4%B8%94%E6%97%A0%E6%8A%A5%E9%94%99%EF%BC%8C%E6%89%80%E6%9C%89%E5%85%B3%E7%B3%BB%E9%83%BD%E8%83%BD%E5%AF%BC%E5%85%A5%E3%80%82%5B%E5%AE%98%E6%96%B9FAQ%E8%AF%B4%E6%98%8E%5D%28https%3A//github.com/apache/incubator-hugegraph-doc/blob/master/content/en/docs/guides/faq.md%29) [](https://go.dosu.dev/discord-bot) [](https://twitter.
com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/apache/incubator-hugegraph/discussions/2917)
GitHub link:
https://github.com/apache/incubator-hugegraph/discussions/2917#discussioncomment-15226420
----
This is an automatically sent email for [email protected].
To unsubscribe, please send an email to: [email protected]