Hey All, having a problem with a column that is un...
# orm-help
k
Hey All, having a problem with a column that is unique and supposed to be nullable. Prisma seems to default everything to 'not null' but I dont see a keyword where to allow now.
k
I have that but its still sending a 'Not Null' to the database DDL
Prisma schema:
Copy code
model Category {
  id            Int        @id @default(autoincrement())
  name          String
  url           String
  pictureSrc    Upload?    @relation(fields: [uploadId], references: [id])
  uploadId      Int?       @unique
  parentId      Int?
  parent        Category?  @relation("CategorySub", fields: [parentId], references: [id], onDelete: NoAction, onUpdate: NoAction)
  subCategories Category[] @relation("CategorySub")
  updatedAt     DateTime   @updatedAt
  createdAt     DateTime   @default(now())
}
let me get a 'real' example
m
Did you run the migration and regenerate client?
k
yes. This is how the DDL is defined in the backend:
Copy code
CREATE TABLE [dbo].[Category](
	[id] [int] IDENTITY(1,1) NOT NULL,
	[name] [nvarchar](1000) NOT NULL,
	[url] [nvarchar](1000) NOT NULL,
	[uploadId] [int] NULL,
	[parentId] [int] NULL,
	[updatedAt] [datetime2](7) NOT NULL,
	[createdAt] [datetime2](7) NOT NULL,
 CONSTRAINT [Category_pkey] PRIMARY KEY CLUSTERED 
(
	[id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY],
 CONSTRAINT [Category_uploadId_key] UNIQUE NONCLUSTERED 
(
	[uploadId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
GO

ALTER TABLE [dbo].[Category] ADD  CONSTRAINT [Category_createdAt_df]  DEFAULT (getdate()) FOR [createdAt]
GO

ALTER TABLE [dbo].[Category]  WITH CHECK ADD  CONSTRAINT [Category_parentId_fkey] FOREIGN KEY([parentId])
REFERENCES [dbo].[Category] ([id])
GO

ALTER TABLE [dbo].[Category] CHECK CONSTRAINT [Category_parentId_fkey]
GO

ALTER TABLE [dbo].[Category]  WITH CHECK ADD  CONSTRAINT [Category_uploadId_fkey] FOREIGN KEY([uploadId])
REFERENCES [dbo].[Upload] ([id])
ON UPDATE CASCADE
ON DELETE SET NULL
GO

ALTER TABLE [dbo].[Category] CHECK CONSTRAINT [Category_uploadId_fkey]
GO
this constraint is the issue:
UNIQUE NONCLUSTERED
Copy code
CONSTRAINT [Category_uploadId_key] UNIQUE NONCLUSTERED 
(
	[uploadId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]