prisma / studio

🎙️ The easiest way to explore and manipulate your data in all of your Prisma projects.
https://www.prisma.io/studio
1.86k stars 47 forks source link

Prisma Studio does violates NOT NULL constraints #1119

Open raamponsah opened 1 year ago

raamponsah commented 1 year ago

I think there is a bug in Prisma. I have tried this with about three different databases services which use MySQL and PostgreSql and they all fail at the"NOT NULL" constraint. Yet I figured that this only happens within the Prisma Studio. If you insert an empty row in the database itself based on your Prisma schema as migrated it will complain about the NOT NULL Constraint violation. Therefore, I believe the bug dwells in the Prisma studio itself.

If you even try with MongoDB/Superbase the Prisma studio will still insert an empty string even if you set the NOT NULL constraint.

There is a bug in Prisma studio that inserts empty strings when NOT NULL has been set.

janpio commented 1 year ago

What exactly is the bug? What goes wrong that should not?

fmrogers commented 11 months ago

I have experience something similar in that a field that is NOT set to be null-able in schema can still have a null value when set in Prism Studio. It appears to be ignoring the constraint.

Vinodjnavalur-zolve commented 9 months ago

@janpio the bug still persists where you can add a null value to a not null constraint column from prisma studio

kodobrody commented 3 months ago

bumping the thread. Just came across the same thing

janpio commented 3 months ago

Can someone please describe the problem in way I can understand? Optimally include an example Prisma schema, and then explain exactly what actions in Prisma Studio lead to an error. Thank you.

BenjaOliva commented 1 month ago

Facing the same issue.

Created a model without optional fields. Went to prisma studio, added a record and allowed me to save null values where i didn't set ? (optional) to those fields.

Am I doing something wrong ?

Example schema:

generator client {
  provider = "prisma-client-js"
}

datasource db {
  provider = "postgresql"
  url      = env("DATABASE_URL")
}

model User {
  uid       String   @id @default(uuid())
  email     String   @unique
  name      String
  phone     String
  verifiedLevel Int @default(1)
  createdAt DateTime @default(now())
  updatedAt DateTime @updatedAt
  ranches   Ranch[]
  source  String
  initialTasksCompleted  Json
  }

So for this user, name and phone for example should be required to create the record and not allow null values... Prisma Studio allowed the record creation with null values

Checked the migration.sql :

 -- CreateTable
CREATE TABLE "User" (
    "uid" TEXT NOT NULL,
    "email" TEXT NOT NULL,
    "name" TEXT NOT NULL,
    "phone" TEXT NOT NULL,
    "verifiedLevel" INTEGER NOT NULL DEFAULT 1,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,
    "initialTasksCompleted" JSONB NOT NULL,

    CONSTRAINT "User_pkey" PRIMARY KEY ("uid")
);