nicolewhite / neo4j-flask

Flaskr Extended with Neo4j and Py2neo.
http://nicolewhite.github.io/neo4j-flask/
312 stars 114 forks source link

Constraint already exists: CONSTRAINT ON ( user:User ) ASSERT user.username IS UNIQUE #16

Closed Antwnina closed 7 years ago

Antwnina commented 7 years ago

I'm trying to run it for the second time and i have constraint exception: ~/Desktop/flasktest/nicolewhite-neo4j-flask-27476c5$ python run.py Traceback (most recent call last): File "run.py", line 1, in from blog import app File "/home/antonina/Desktop/flasktest/nicolewhite-neo4j-flask-27476c5/blog/init.py", line 4, in graph.schema.create_uniqueness_constraint("User", "username") File "/usr/local/lib/python2.7/dist-packages/py2neo/database/init.py", line 775, in create_uniqueness_constraint {"property_keys": [property_key]}) File "/usr/local/lib/python2.7/dist-packages/py2neo/database/http.py", line 212, in post raise_from(GraphError(message, **content), error) File "/usr/local/lib/python2.7/dist-packages/py2neo/util.py", line 122, in raise_from raise exception py2neo.database.status.ConstraintViolationException: Constraint already exists: CONSTRAINT ON ( user:User ) ASSERT user.username IS UNIQUE

How it can be solved?

ScottMcCormack commented 7 years ago

A first approach could be to comment out the following three lines in neo4j-flask/blog/__init__.py

graph.schema.create_uniqueness_constraint("User", "username")
graph.schema.create_uniqueness_constraint("Tag", "name")
graph.schema.create_uniqueness_constraint("Post", "id")

So that these are not executed at runtime.

A better approach would be to test the constraints for existence and continue if found. I'm not sure what a best approach would be for managing this in a Flask application.