解决 Grafana 报错 dashboard with the same UID already exists 导入冲突修复
排查 Grafana 导入仪表盘 JSON 抛出 dashboard with the same UID already exists,分析 UID 唯一性约束与覆盖选项。
问题现象
在 Grafana UI 或通过自动化 CI/CD 导入仪表盘 JSON 时失败:
HTTP 400 Bad Request
{"message":"A dashboard with the same UID already exists","status":"bad-request"}
触发根因
- 当前导入的 JSON 中声明的
uid字段已在 Grafana 内部被其他文件夹下的仪表盘占用; - 导入 API 请求中缺少
"overwrite": true参数,Grafana 默认禁止静默覆盖同名/同 UID 仪表盘。
解决步骤
通过 API 导入时启用 overwrite 标志
在向 /api/dashboards/db 发起 POST 请求的载荷中指定允许覆盖:
{
"dashboard": { ... },
"overwrite": true,
"folderId": 0
}
若需创建为独立新仪表盘,修改或清空 uid 字段
直接在 JSON 中删除 "uid": "abc12345" 或赋值为 null,Grafana 将自动分配全局唯一的新 UID。
验证确认
重新执行导入命令:
curl -X POST -H "Content-Type: application/json" -H "Authorization: Bearer <TOKEN>" \
http://localhost:3000/api/dashboards/db -d @dashboard.json
返回 HTTP 200 {"status":"success"},仪表盘导入成功。


