1

I have a company node where the name should be unique:

class Company(StructuredNode):
    name = StringProperty(unique_index=True)
    participated = ArrayProperty(StringProperty())

However, when I run the code TWICE to create the company, it creates two nodes with the exact same name:

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()

Two Nodes with Identical Names, Despite Unique_Index on Name

Is there a reason that this constraint isn't being enforced?

Thanks!

Phillip Ng
  • 45
  • 6
  • You should be using `unique=True` to avoid having two nodes with the same value for a field. `unique_index=True` allows for the database to query values faster based on the field, as specified in the [Neo4j documentation](https://neo4j.com/docs/cypher-manual/current/constraints/#_implications_on_indexes), but I'm not sure why it still allows you to have two of the same value in that case. If anyone knows precisely what `unique_index=True` does, more info would be greatly appreciated. – Ethan Posner Jun 23 '22 at 03:58

0 Answers0