2017-04-12 37 views
0

只有在通過查詢存在約束條件時纔有任何方法來刪除約束條件?我正在使用JavaScript的螺栓驅動程序。Neo4j丟棄約束條件(如果存在的話)

我最初以爲我只是趕上了錯誤,但我得到的錯誤是不夠清楚:

{"code":"Neo.DatabaseError.Schema.ConstraintDropFailed"} 
{ Error: An unexpected failure occurred, see details in the database logs, reference number .... } 

在日誌中我確實得到:

Unable to drop CONSTRAINT ... No such constraint CONSTRAINT 

但我不不想以編程方式打開日誌並解析它。

是否有任何方法只有在存在時才刪除約束?我沒有找到有用的東西。

我能想到的唯一的事情就是先嚐試創建兩個與約束衝突的節點(它會返回一個更清晰的錯誤),但我更喜歡更清晰的東西。

+0

您是否正在丟棄然後創建新約束? –

回答

0

如果您知道所需的所有索引和約束,則可以使用apoc過程apoc.schema.assert來確保它們存在,並且刪除所有其他現有索引和約束。

如何使用此程序的一個示例是此doc section的一部分。這裏是顯示調用過程和結果的片段:

Let’s create some indexes and constraints, note that other indexes and constraints will be dropped by this. 

CALL apoc.schema.assert(
    {Track:['title','length']}, 
    {Artist:['name'],Track:['id'],Genre:['name']}); 

╒════════════╤═══════╤══════╤═══════╕ 
│label  │key │unique│action │ 
╞════════════╪═══════╪══════╪═══════╡ 
│Track  │title │false │CREATED│ 
├────────────┼───────┼──────┼───────┤ 
│Track  │length │false │CREATED│ 
├────────────┼───────┼──────┼───────┤ 
│Artist  │name │true │CREATED│ 
├────────────┼───────┼──────┼───────┤ 
│Genre  │name │true │CREATED│ 
├────────────┼───────┼──────┼───────┤ 
│Track  │id  │true │CREATED│ 
└────────────┴───────┴──────┴───────┘