KWriter
KWriter

Reputation: 1184

Removing a constraint from node using Cypher

I know that the following code says that every node with the label City has a unique value for the location property.

CREATE CONSTRAINT ON (c:City)
ASSERT c.location IS UNIQUE;

So this code forbids me to have two cities with the same name in one country, e.g. there can be only one London in England. Now I need to turn the constraint off. How can I do that?

Upvotes: 0

Views: 363

Answers (1)

amanb
amanb

Reputation: 5473

There is no way to "switch off" a constraint. You have to drop it using the DROP CONSTRAINT command. This will delete the constraint.

Make sure you have the constraint name before dropping it. If you are not sure about the constraint name, then you can list all constraints using the SHOW CONSTRAINTS command. It is always a good practice to specify a constraint name when creating it. In the below example, I specified the constraint name as constraint_city:

CREATE CONSTRAINT constraint_city ON (c:City)
ASSERT c.location IS UNIQUE;

Then, to drop the constraint:

DROP CONSTRAINT constraint_city;

Upvotes: 1

Related Questions