I'm using Hasura as backend for react app.
In my SQL table I set up a field, let's say "identification_number" as [text, unique, nullable]. So identification_number might be null, but if it is not null, it should be unique across the table.
But sometimes fronted sends me data with an empty string as a value of my field.
{
name: "asdfomw",
year: "2010",
identification_number: "",
description: "some description"
}
In this situation Hasura successfully adds record to database. But if an empty string is present in the payload for some other record, I get an error of "unique violation", because there are two records with equal identification_number having values of "".
So I think of two possible solutions for this problem:
- Automatic conversion of empty-strings to nulls.
- Adding constraints to Hasura scheme, not allowing empty strings for certain columns.
And I don't have answers for any of this questions.