neo4j Neomodel:unique_index在StringProperty()上不起作用

h43kikqp  于 12个月前  发布在  其他
关注(0)|答案(1)|浏览(107)

我有一个公司节点,其中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()

有没有理由不强制执行这个约束?
谢谢你,谢谢

5cg8jx4n

5cg8jx4n1#

unique_index=True是要使用的正确字段。
我也遇到了同样的问题,这是由于没有安装索引和约束指令造成的,如下所述:https://neomodel.readthedocs.io/en/latest/configuration.html#enable-automatic-index-and-constraint-creation

from neomodel import install_labels
install_labels(Company)

相关问题