hey, i am looking to add not null constraint to a ...
# orm-help
l
hey, i am looking to add not null constraint to a column depending on value of another column in postgres , which will be like below:
Copy code
CREATE TABLE my_table
(
id serial,
attribute boolean,
number integer,
CONSTRAINT if_attribute_then_number_is_not_null 
   CHECK ( (NOT attribute) OR (number IS NOT NULL) ) 
) ;
if i do directly on postgres. But i dont see any documentation mentioning how this can be done in prisma, so i am wondering if this feature is there in prisma yet or its not supported ?
i
As far as I'm concerned you can generate prisma migration based on prisma schema, however without the constraint. I also haven't seen it in the documentation, so my assumption is it's not possible. You could add this constraint in the migration manually.
l
Thanks @Irek Prucnal for quick response. I have tried to do it manually in migration file but that is creating problem in typescript part, where it is showing error " field cannot be null ".
as i want the field to be not null always except a specific condition.