Search code examples
py2neo

py2neo Cypher Transaction "Create Index on..."


I'am trying to create indexes in an empty neo4j 2.1.2 Database using py2neo (1.6.4)

I tried the following code:

from py2neo import cypher

session = cypher.Session("http://localhost:7474")
tx = session.create_transaction()
tx.append("CREATE INDEX ON :Net(name)")
tx.append("CREATE INDEX ON :Key(name)")
tx.append("CREATE INDEX ON :Prop(name)")
tx.commit

The code is running without errors, but nothing is done with the database.

If I do the check in the neo4j browser entering

:schema

I get the answer

No indexes

No constraints

If I enter the cypher query by hand

CREATE INDEX ON :Net(name)

followed by

:schema

I get the correct answer

Indexes

  ON :Net(name) ONLINE  

No constraints

What am I doing wrong?


Solution

  • You need to use tx.commit(), not tx.commit. Your code is running without error because tx.commit is printing the tx.commit method, which is fine to do but if you want to send the transactions use tx.commit().