cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Not able to create multiple constraints through code, even after using different session for each call

Issue

Not able to create multiple constraints through code.

  • Neo4j version: Community 4.0.3
  • Neo4j Mode: Single instance
  • Driver version: Javascript : "4.0.0",
  • Operating system: Mac OS

Steps to reproduce

I am creating some constraint statements for my neo4j DB through code, and I loop through all of them and create the respective cypher statements:


//loop through constraints
const statement = `CREATE CONSTRAINT ON (${name}:${type}) ASSERT ${name}.${parameter} IS UNIQUE`

runConstraint(driver, statement)
function runConstraint(driver, constraintStatement) {
  var session = driver.session()
  return session
    .run(constraintStatement)
    .then((result) => {
      session.close()
      console.log('result : ', result)
    })
    .catch((error) => {
      session.close()
      console.log('error : ', error)
    })
}

Expected behavior

The code should create all the constraints one by one, since I'm using a new session object for each call. Shouldn't each Session.close commit the transaction?

Actual behavior

After the first constraint is created, I get:

error : Neo4jError: Database constraints have changed (txId=26) after this transaction (txId=1) started, which is not yet supported. Please retry your transaction to ensure all constraints are executed.

0 REPLIES 0