Prisma allowing empty DB fields
Hey guys. Day one of using Prisma, so probably something simple Im missing or not understanding. From reading docs, if no type modifer is provided, the default behaviour is fields are not null. That being said, it is letting me submit records without certain fields missing. I have created records through both my TRPC endpoint, and Prisma Studio, and in both I can omit a field and it doesn't reject it. Attached a screenshot of my model and an example record. Any ideas?
8 Replies
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
I don't want them optional, thats the issue. I want them mandatory, have not added the ?, yet it allows records with empty fields
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
Anyway I can check? when I click into the field in prisma studio it shows null
I can use do a minimum length on the TRPC endpoint with z.string().min(3) but would rather have the validation at the DB level itself
Hey Cody, isn't this tied to what DB you're using rather than Prisma only?
Like generally if you don't add a question mark, if the DB Supports it, it should not be null.
Just using default sqlite for dev, haven't tested on deployment which is using Planetscale
I'll give it a shot in prod db and see what happens