#6 Digit unique number for the database schema
10 messages · Page 1 of 1 (latest)
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/random
you can use this method to generate a random number
The Math.random() static method returns a floating-point, pseudo-random number that's greater than or equal to 0 and less than 1, with approximately uniform distribution over that range — which you can then scale to your desired range. The implementation selects the initial seed to the random number generation algorithm; it cannot be chosen or r...
Oh, Thank you, I ended up doing that, I was asking as I wanted to know if there is something built in, instead I used a recursive function that checks if the generated code is equal to an existing one and if not then reutrn that
You have @unique that will not let two records have the same number with the same field
will throw an error
also if you only want to store numbers, then the appropriate type would be Int
not String, because you are storing numbers.
error you'll prolly get: https://www.prisma.io/docs/orm/reference/error-reference#p2002
Thank you