Hi there, Suppose I want a column in a table to on...
# orm-help
a
Hi there, Suppose I want a column in a table to only have int's in the range [0,5], i.e. {0,1,2,3,4,5}, how do I specify that in the prisma schema file? Using this with postgresql. Would use this to implement ratings in my database.
n
Hey Abhishek 👋 You could enforce this by enums and also by a check constraint. You could add a constraint in your database like this
Copy code
alter table ratings
   add constraint check_rating
   check (rating between 0 and 5);
You won’t need to define this in schema file, you can define the rating column in your model file as Int and enforce the above constraint on your database, entering any other values except [0..5] will throw an error
a
thanks! This was helpful. I would go the enum route. Would you recommend which method is better for specific reasons?