Cypher Indexes and Constraints Course - Creating a Node Key Constraint

When I try to run the following query to complete this lesson, I get an error message.
CREATE CONSTRAINT Person_name_url_nodekey IF NOT EXISTS FOR (x:Person) REQUIRE (x.name,x.url) IS NODE KEY

Error message:

Neo.DatabaseError.Schema.ConstraintCreationFailed

Unable to create Constraint( type='NODE KEY', schema=(:Person {name, url}) ): Node(11941) with label Person must have the properties (name, url)

Any idea why this is happening? I tried looking up the node with ID 11941 but nothing was being returned.

It looks like the Person node doesn´t have the properties name and url
I´ve run the same query in my Graph where I Know theres not name and url properties in my node "RESPONSABLE" and i get the same error message :

Neo.DatabaseError.Schema.ConstraintCreationFailed

Unable to create Constraint( type='NODE KEY', schema=(:RESPONSABLE {name, url}) ): Node(11578) with label RESPONSABLE must have the properties (name, url)

try this to see if properties are present :

MATCH(p:Person) RETURN keys(p) LIMIT 1
or this other by Id
MATCH (p:PERSON) WHERE id(p)=11941 RETURN keys(r)

greetings

correction to the second query

MATCH (p:PERSON) WHERE id(p)=11941 RETURN keys(p)

That does look like the issue. Maybe just try to find nodes that don’t have those two required properties.

MATCH(p:Person)
WHERE p.name is null or p.url is null
RETURN id(p)

I tried running the query again the next day and it worked. Not sure what the problem was.

1 Like