我有一个公司节点,其中name
应该是唯一的:
class Company(StructuredNode):
name = StringProperty(unique_index=True)
participated = ArrayProperty(StringProperty())
然而,当我运行代码TWICE来创建公司时,它创建了两个名称完全相同的节点:
from neomodel import db
import graph_db
from graph_db.model import Company, Employee, Position, Department, Metric
with db.write_transaction:
acme_inc = Company(name="Acme Inc", participated=[2021]).save()
有没有理由不强制执行这个约束?
谢谢你,谢谢
1条答案
按热度按时间5cg8jx4n1#
unique_index=True
是要使用的正确字段。我也遇到了同样的问题,这是由于没有安装索引和约束指令造成的,如下所述:https://neomodel.readthedocs.io/en/latest/configuration.html#enable-automatic-index-and-constraint-creation