# How to enforce a field to be unique?

**URL:** <https://forum.weaviate.io/t/how-to-enforce-a-field-to-be-unique/91>\
**Category:** Support\
**Created:** [May 26, 2023, 3:57pm UTC](https://forum.weaviate.io/t/how-to-enforce-a-field-to-be-unique/91 "2023-05-26T15:57:11Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jpiabrantes](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.weaviate.io/jpiabrantes/32/89_2.png) [@jpiabrantes](https://forum.weaviate.io/u/jpiabrantes)\
**Post date:** [May 26, 2023, 3:57pm UTC](https://forum.weaviate.io/t/how-to-enforce-a-field-to-be-unique/91/1 "2023-05-26T15:57:12Z")

</div>

I want to avoid duplicates. For that reason, I want to enforce one of the fields to be unique. How can I do this?

---

<div class="post-metadata">

**Author:** ![jphwang](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.weaviate.io/jphwang/32/38_2.png) [@jphwang](https://forum.weaviate.io/u/jphwang)\
**Post date:** [June 5, 2023, 12:23pm UTC](https://forum.weaviate.io/t/how-to-enforce-a-field-to-be-unique/91/2 "2023-06-05T12:23:16Z")

</div>

Hi @jpiabrantes -

The only unique field in Weaviate currently is the `uuid`. So, one way you could do that is to generate your object ID based on your desired unique field.

If you wanted to do that with the title, you can try:

```python
from weaviate.util import generate_uuid5

class_name = "YourClassName" # Replace with your class name
data_objs = [
    {"title": f"Object {i+1}"} for i in range(5) # Replace with your actual objects
]
with client.batch() as batch:
    for data_obj in data_objs:
        batch.add_data_object(
            data_obj,
            class_name,
            uuid=generate_uuid5(data_obj["title"])  
        )

```
