how to make a attribute unique and it should be optional so it can store null or empty string
- 0
- Flutter

its giving error while leaving the optional field as empty because field is already empty string that is why its giving error. AppwriteException: document_already_exists, Document with the requested ID already exists. (409)

any one kows the solution ?

Are you manually setting the document ID? Are you using a SDK?

For the unique attribute take a look at: https://github.com/appwrite/appwrite/discussions/1492

both

Can you share the code?

You can use the console to check if there's already a document with the id you are passing.

Also note that if you mark an attribute as unique and try to create two documents with same value for unique attribute the error message is the one you mentioned AppwriteException: document_already_exists, Document with the requested ID already exists. (409)
with no indication about which attribute is causing the error.

yes i know about this

Are you making sure to pass null rather than empty string?

yes sending null

yes sending null and also tried empty string but its not working for unique attribute

What's your code? Can you do a get collection on the collection and share the output?

it definitely should work. In the screenshot below i have a unique index on s
and the first two documents have s
set to null

not using console ,
here is my code
databaseId: databaseId,
collectionId: productDataCollectionId,
documentId: documenId,
data: {
"sellingPrice": price,
"totalQuantity": quantity,
"productName": pname,
"image": imageUrl,
"itemCode":null,
});```

It shouldn't matter whether it's from the console or not since it's the same API.
Please share your collection as JSON

Now its working,

but why its storing empty string if sending data like itemCode:""
, and this empty string is not showing in appwrite console ,

due to this empty string i am getting document with request id is alredy exist.

what do you mean?

please share your collection as JSON
Recommended threads
- Support for postgreSQL and mongoDb
By when can we expect Appwrite to have support for PostgreSQL and MongoDB, and I hope that along with that, storing and querying of nested objects will also be ...
- Error response from daemon: driver faile...
on endpoint appwrite-traefik (00bbc10e5875d0c367d8975c6abc946a77b7ec201a64a825399add44fb34ebb4): failed to bind port 0.0.0.0:80/tcp: Error starting userland pro...
- "Memberships privacy" setting in 1.7.4
Hi everyone, I'm experiencing an issue with a clean self-hosted installation of Appwrite version 1.7.4. I previously used version 1.6.1, and if I remember corre...
