# Relationships are not created when adding them dynamically

**URL:** <https://community.neo4j.com/t/relationships-are-not-created-when-adding-them-dynamically/64862>\
**Category:** Cypher\
**Tags:** cypher, import\
**Created:** [November 6, 2023, 7:32pm UTC](https://community.neo4j.com/t/relationships-are-not-created-when-adding-them-dynamically/64862 "2023-11-06T19:32:49Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hatem](https://avatars.discourse-cdn.com/v4/letter/h/aca169/32.png) [@Hatem](https://community.neo4j.com/u/Hatem)\
**Post date:** [November 6, 2023, 7:32pm UTC](https://community.neo4j.com/t/relationships-are-not-created-when-adding-them-dynamically/64862/1 "2023-11-06T19:32:49Z")

</div>

Hello,

Using the latest Neo4j docker container, I'm trying to create a graph for which there are many different node labels and relationships, therefore, I can't hard code each node label and relationship in the create query. I tried to do this programmatically (see code below), the code runs without problems, the nodes are getting created, however the relationships are not (the relationships don't appear in the Neo4j Browser). I made sure that the nodes are create and have the necessary constraints and property indexes. Can anyone please help me understand why the relationships are not added?

Here is the code for adding the relationships: (`meta_graph` in the first line is a list that contains triplets of `subject_node`, `object_node` and `relation`.)  
``

`
```
for subject_node, relation, object_node in meta_graph:
    query = """
    LOAD CSV WITH HEADERS FROM "file:///input.csv" AS row
    FIELDTERMINATOR ';'
    MATCH (s:%s {id: row.id_subj, title: \"row.subject\"})
    MATCH (o:%s {id: row.id_obj, title: \"row.object\"})
    MERGE (s)-[r:%s {id: toInteger(row.id_relation)]->(o)
    """ % (subject_node, object_node, relation)

    _driver.execute_query(query, database_="neo4j")

```
`

Thanks!

---

<div class="post-metadata">

**Author:** ![glilienfield](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/glilienfield/32/27534_2.png) [@glilienfield](https://community.neo4j.com/u/glilienfield)\
**Post date:** [November 6, 2023, 8:39pm UTC](https://community.neo4j.com/t/relationships-are-not-created-when-adding-them-dynamically/64862/2 "2023-11-06T20:39:01Z")

</div>

Can you share the query you use in the browser? Did you explicitly return the relationships in your browser query?

BTW- you can use single quotes to enclose a string in cypher, so you can use them if you don't want to except your double quotes in your cypher string.

---

<div class="post-metadata">

**Author:** ![Hatem](https://avatars.discourse-cdn.com/v4/letter/h/aca169/32.png) [@Hatem](https://community.neo4j.com/u/Hatem)\
**Post date:** [November 6, 2023, 9:07pm UTC](https://community.neo4j.com/t/relationships-are-not-created-when-adding-them-dynamically/64862/3 "2023-11-06T21:07:20Z")

</div>

@glilienfield, Thanks for the quotes tip 👍

This is the query that I used to check for the relations:  
`
MATCH ()-[r]->()
RETURN r;
`

It returns (no changes, no records). In order to make sure that it can really MATCH with the nodes, I manually selected some labels of the `meta_graph` list, hardcoded the labels in the query, and it returned the target nodes.

Also on the left-hand side screen of the browser, it doesn't show any info. about the relationships, here is a screenshot:  
 ![image](https://us1.discourse-cdn.com/flex021/uploads/neo4jcommunity/original/3X/9/2/9273466998ca6d1956921fd14e59888ddb07fe0e.png)

For the Node labels section, it shows the total number of the nodes and their labels.

---

<div class="post-metadata">

**Author:** ![glilienfield](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/glilienfield/32/27534_2.png) [@glilienfield](https://community.neo4j.com/u/glilienfield)\
**Post date:** [November 6, 2023, 9:20pm UTC](https://community.neo4j.com/t/relationships-are-not-created-when-adding-them-dynamically/64862/4 "2023-11-06T21:20:41Z")

</div>

The fact that the browser is showing there is no relationships in the database AND your simple query above returns zero results, I suspect the relationships were not created.

Can you run the creation query above in the browser to see what happens? Can you try with a small sample of the rows?

---

<div class="post-metadata">

**Author:** ![glilienfield](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/glilienfield/32/27534_2.png) [@glilienfield](https://community.neo4j.com/u/glilienfield)\
**Post date:** [November 7, 2023, 10:20am UTC](https://community.neo4j.com/t/relationships-are-not-created-when-adding-them-dynamically/64862/5 "2023-11-07T10:20:00Z")

</div>

Why do you use the toInteger function for the relationship’ id, but not for the node id’s?

---

<div class="post-metadata">

**Author:** ![Hatem](https://avatars.discourse-cdn.com/v4/letter/h/aca169/32.png) [@Hatem](https://community.neo4j.com/u/Hatem)\
**Post date:** [November 8, 2023, 9:11am UTC](https://community.neo4j.com/t/relationships-are-not-created-when-adding-them-dynamically/64862/6 "2023-11-08T09:11:10Z")

</div>

Exactly.. The error was that I didn't cast the nodes ids and it was faulting silently.. I fixed it by casting the id of Nodes `s` and `o` 🙂 .. Thanks a lot @glilienfield!
