Hey there! I have the following field on my user:...
# mongodb
p
Hey there! I have the following field on my user:
Copy code
model User {
    id    String @id @default(auto()) @map("_id") @db.ObjectId
    name  String
    phone String? @unique()
}
As you can see, the phone number is optional and unique. Yet when I register a user without a phone number, I cannot register a second user without a phone number, as I get the error "Unique constraint failed on the constraint: 'User_phone_key' ". Any way to say that
null
is not a phone number and that it should not get counted as a unique value?
1
d
You'll need to manually create a partial index on
phone
and not use prisma migrate because that one creates a full unique index, not a partial one.
p
Alright then, thanks very much!