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:

Table B:

Relationships
Table A:

Table B:

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:
- Created 4 years ago
- Reactions:6
- Comments:25 (8 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@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.
@0x777 Is this issue still being worked on? Do you have an estimate when this could be fixed? Thanks!