Skip to content

Null constraint violation on the fields error does not specify fields when the problem is a NOT NULL custom domain #7254

Open

Description

@andrerpena

Bug description

Inserts that violate a NULL constraint normally tell you which fields are the causing the problem.
However, if the constraint is caused by a custom Postgres domain, it does not tell you.

The message will be like this:

Invalid `prisma.schemaVersion.create()` invocation:
  Null constraint violation on the fields: ()
    at cb (/Users/andrepena/git/hyperforms/hyperforms-web/node_modules/@prisma/client/runtime/index.js:35101:17)
    at processTicksAndRejections (internal/process/task_queues.js:95:5) {
  code: 'P2011',
  clientVersion: '2.23.0',
  meta: { constraint: [] }
}

Note that the fields that caused the problem are omitted. Also, because I don't think it's possible to tell Prisma to show the raw SQL error, it's impossible to know where the problem is

How to reproduce

Create a postgres domain that does NOT accept NULL

CREATE DOMAIN public.nano_id VARCHAR(16) NOT NULL;

Use this domain in a table

CREATE TABLE public.schema_versions (
    display_name character varying NOT NULL,
    my_field public.nano_id
);

Try to create a record that does not include my_field. See that my_field itself is nullable. The problem is that the domain is not nullable.

Expected behavior

The original SQL error should not be omitted. Right now, it's impossible to see the original error message

SQL Error [23502]: ERROR: domain nano_id does not allow null values

If possible, it should list the error in the Null constraint error

Null constraint violation on the fields: (my_field)

Prisma information

model SchemaVersion {
displayName String @Map("display_name") @db.VarChar
my_field String
@@Map("schema_versions")
}

Environment & setup

  • OS: MacOS
  • Database: Postgres
  • Node.js version: 14.17

Prisma Version

"@prisma/client": "^2.23.0",

Activity

  1. added
    kind/bug
    on May 24, 2021
  2. pantharshit00 commented on May 28, 2021

    @pantharshit00
    Contributor

    I don't think we properly support postgres domains right now so this is kind of expected.

    I am marking this as a feature request.

  3. janpio commented on May 28, 2021

    @janpio
    Contributor

    Related: #1796

  4. changed the title [-]"Null constraint violation on the fields" error does not specify fields when the problem is a NOT NULL custom domain[/-] [+]`Null constraint violation on the fields` error does not specify fields when the problem is a `NOT NULL` custom domain[/+] on Jan 30, 2024
  5. janpio commented on Jan 30, 2024

    @janpio
    Contributor

    This could also be a feature request to return the raw SQL error on P2011.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions