neo4j - 无法创建约束
问题描述
我的数据看起来像:
user_id from_page_id to_page_id event_type timestamp
0 USER355A155307089387404434774906 pages/mine/mine pages/mine/mine pv 1598936406406
1 USER355A155307089387404434774906 pages/mine/mine /pages/score/score pv 1598936408261
2 USER355A155307089387404434774906 pages/mine/mine pages/mine/mine click 1598936408311
3 USER355A155307089387404434774906 pages/mine/mine /pages/score/score click 1598936410824
4 USER355A155307089387404434774906 pages/score/score /pages/scoreDetai pv 1598936410878
...
我正在尝试创建一个图表以将用户与其访问的页面路径联系起来:
LOAD CSV WITH HEADERS FROM "file:///data.csv" AS line
CREATE (u:User), (p1:Page {from: line.from_page_id}), (p2:Page {to: line.to_page_id}),
(u)-[:VIEWS]->(p1), (u)-[:VIEWS]->(p2), (p1)-[:NEXT]->(p2);
CREATE CONSTRAINT ON (u:User) ASSERT u.id IS UNIQUE;
它创建图表,但它给了我错误:
Neo.DatabaseError.Schema.ConstraintCreationFailed: Unable to create Constraint( name='constraint_47e7f15d', type='UNIQUENESS', schema=(:User {id}) ):
Both Node(324) and Node(327) have the label `User` and property `id` = 'USER0138119929164105321108358370'
我在这里做错了什么?
解决方案
这有什么帮助:
在单独的过程中创建约束.. 它不必是您的密码的一部分。请注意,您只能在没有重复项的情况下创建 CONSTRAINT。
一旦 CONSTRAINT 存在,Neo4j 将检查并防止插入任何重复项。
当您拥有数据时,您应该使用
MERGE (u:User {user_id:line.user_id})
更多信息:https ://neo4j.com/docs/cypher-manual/current/clauses/merge/
推荐阅读
- vhdl - 手动更改时钟值时,rising_edge(clk) 未检测到边沿
- delphi - 无法在主窗体中完全看到 MDI 子窗体
- python - 递归创建二叉搜索树的函数
- list - 存储在列表中的键并在 keyExtractor 中使用它们
- xamarin - Xamarinn 的新手可以拖放 UI 吗?
- javascript - JSON 中的最大值
- javascript - 当有人点击我页面上的任何链接时打开两个标签
- c++ - 类似于 `declval` 的概念
- ansible - Hashicorp Vault 通过 Ansible 解封错误
- php - 在 PHP 中使用准备好的语句将数据插入数据库失败,没有报告错误