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.

NullConstraintViolation

See original GitHub issue

I have the following models (simplified for reporting the issue):

model User {
  id         String        @default(cuid()) @id @unique
  email      String        @unique
  staff      Staff?
}

model Staff {
  id        String   @default(cuid()) @id @unique
  user      User
  active    Boolean?
}

When trying to add a user with the following query

mutation {
  createOneUser (data: {
    email: "user@gmail.com"
  }) {
    id
    email
  }
}

I get the following error

"error": "ConnectorError(NullConstraintViolation { field_name: \"User.staff\" })"

This seems odd, since the staff field in the User model is optional. I have other 1-1 relations with the same problem.

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
pantharshit00commented, Jul 15, 2019

Thanks, I can confirm all of this. Most of them related to the query engine so I am going to transfer this issue.

0reactions
pantharshit00commented, Aug 5, 2019

I can no longer reproduce any of these conditions now with prisma2@2.0.0-preview-5, binary version: 29f6d9f7f6d0a85cc30df1809733612bab56a1c5

These have been fixed between the updates

Read more comments on GitHub >

github_iconTop Results From Across the Web

Null constraint violation on the fields: (`id`) · Issue #498 - GitHub
Bug description Unable to use @default(autoincrement()). Keep getting PrismaClientKnownRequestError: Invalid `client.user.create()` ...
Read more >
null value in column violates not-null constraint PostgreSQL
1 Answer 1 · ERROR: column "v_id" is in a primary key SQL state: 42P16 · i can't fill records in v_id because...
Read more >
Integrity constraint violation: 19 NOT NULL constraint failed
Hi everyone, I'm very new to laravel, this is my first project and I need little help. I'm getting this error but I'm...
Read more >
How to Solve Not Null Constraint Violation in Target Table?
If we disable the constraint for target table to do the bulk load instead of normal load , and target table gets some...
Read more >
Bizzarre insert behavior: NULL constraint violation with non ...
Bizzarre insert behavior: NULL constraint violation with non-null value, column changes every run. 393 views.
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