question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

One to One relationship causing Not-Null Constraint Violation on Nested Data Insert

See original GitHub issue
{
  "errors": [
    {
      "extensions": {
        "path": "$.selectionSet.insert_a.args.objects[0]",
        "code": "constraint-violation"
      },
      "message": "Not-NULL violation. null value in column \"id\" violates not-null constraint"
    }
  ]
}

The following table definitions reproduce the above error:

Tables

Table a:

Screenshot 2019-07-20 at 14 58 23

Table B:

Screenshot 2019-07-20 at 14 58 42

Relationships

Table A:

Screenshot 2019-07-20 at 14 59 54

Table B:

Screenshot 2019-07-20 at 15 00 10

Invoking The Error

That error happens when inserting data from the “has one” side (table a), but not when inserting from the “belongs to” side (I wish Hasura could label relationships like this as well in addition to what’s there to make things clear quickly):

the above error happens when you run this query:

mutation {
  insert_a(objects: {
    junk_a: "This is a's junk"
    b:{
      data: 
        {
          junk_b: "B's junk inserted when inserting a's junk"
        }
    }
  }){
    affected_rows
  }
}

but not when you run this query from the other side:

mutation {
  insert_b(objects: {
    junk_b: "This is B's junk"
    a:{
      data: 
        {
          junk_a: "A's junk inserted when inserting B's junk"
        }
    }
  }){
    affected_rows
  }
}

This could be related to #2508, but I am not sure cause what he is reporting on is different.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:6
  • Comments:25 (8 by maintainers)

github_iconTop GitHub Comments

7reactions
corsali-albertcommented, Jun 26, 2021

@eviefp Is there a PR or commit I can track to see when this actually lands? I’m on 2-beta2 and still hitting this.

7reactions
beepsoftcommented, Nov 19, 2019

@0x777 Is this issue still being worked on? Do you have an estimate when this could be fixed? Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

ERROR: null value in column "id" of relation xxx violates not ...
PSQLException: ERROR: null value in column "id" of relation "product" violates not-null constraint Detail: Failing row contains (null, Dress, ...
Read more >
How to manage JPA bidirectional relationships properly
In this throubleshooting guide, we will explore the importance of maintaining data integrity in JPA/Hibernate bidirectional relationships.
Read more >
Hibernate @NotNull vs @Column(nullable = false) - Baeldung
ConstraintViolationException. It's important to notice that Hibernate didn't trigger the SQL insert statement. Consequently, invalid data wasn't ...
Read more >
The best way to map a @OneToOne relationship with JPA and ...
Learn the best way to map a OneToOne association with JPA and Hibernate when using both unidirectional and bidirectional relationships.
Read more >
SQLite Foreign Key Support
One solution is to add an SQL foreign key constraint to the database schema to enforce the relationship between the artist and track...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found