'Prisma ORM Postgres SQL DB Schema Not Null Fields

Just so you have it here is my defined prisma schema.

Now if I read correctly in the prisma docs it said, that every field in which I do not declare a ? after the type, it should be presented as not null, in a relational database. This is the mentioned Section in the Docs.

// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema

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

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

model Users {
  id          String      @id @default(uuid())
  createdAt   DateTime    @default(now())
  updatedAt   DateTime    @updatedAt
  email       String      @unique
  password    String
  role        Roles       @default(USER)
  contact     Contacts?   @relation(fields: [contactId], references: [id])
  contactId   String?
}

enum Roles {
  USER
  ADMIN
}

model Contacts {
  id          String    @id @default(uuid())
  createdAt   DateTime  @default(now())
  updatedAt   DateTime  @updatedAt
  firstName   String
  lastName    String
  email       String    @unique
  phone       String
  addressLine String
  city        String
  zipCode     Int
  note        String
  Users       Users?
  events      ContactsOnEvents[]  @relation(name: "guest")
  guests      ContactsOnEvents[]  @relation(name: "guestfrom")
}

model Events {
  id          String      @id @default(uuid())
  createdAt   DateTime    @default(now())
  updatedAt   DateTime    @updatedAt
  name        String
  startDate   DateTime
  EndDate     DateTime
  type        EventTypes  @default(HUNT)
  contacts    ContactsOnEvents[]
}

enum EventTypes {
  HUNT
  EVENT
}

model ContactsOnEvents {
  guest       Contacts  @relation(fields: [guestId], references: [id], name: "guest")
  guestId     String
  guestFrom   Contacts  @relation(fields: [guestFromId], references: [id], name:"guestfrom")
  guestFromId String
  event       Events    @relation(fields: [eventId], references: [id])
  eventId     String
  assignedAt  DateTime  @default(now())
  type        Types[]   

  @@id([guestId, eventId])
}


enum Types {
  HUNTER
  DRIVER
  SEEKER
}

So in this schema I think most of the fields should be not null fields, but when I open it in Prisma studio most of my fields are nullable, ist that some sort of config Error or is it another wierd bug.

For Refrence here a picture of my user table where every field except the contact relation should not be null. Instead all Fields are nullable here cause required fields should be red.

Picture of User in prisma studio

So thanks for the help everyone.

Addition This is my Schema for the Users table itself

Users Table

After seeing this I of course tried if it would get into the databse and it does.

enter image description here



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source