# Validates\_uniqueness\_of in update

**URL:** <https://www.ruby-forum.com/t/validates-uniqueness-of-in-update/147523>\
**Category:** Rails\
**Created:** [September 2, 2008, 7:51pm UTC](https://www.ruby-forum.com/t/validates-uniqueness-of-in-update/147523 "2008-09-02T19:51:19Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![stevel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/4491bb/32.png) [@stevel](https://www.ruby-forum.com/u/stevel)\
**Post date:** [September 2, 2008, 7:51pm UTC](https://www.ruby-forum.com/t/validates-uniqueness-of-in-update/147523/1 "2008-09-02T19:51:19Z")

</div>

I have a problem with the usage of validates\_uniqueness\_of that I  
hope someone can help throw a light on. With a new record, this  
validation works fine. But my problem came when I am updating a  
record. I was not able do it because it tells me that field value  
already exists. I was actually updating the value of other fields.

According to the documentation which says “When the record is updated,  
the same check is made but disregarding the record itself.” And it  
seems like this isn’t happening. Just wondering what is it that I am  
not doing correctly. I am using Rails 2.1.0

Thanks in advance for your inputs,

Steve

---

<div class="post-metadata">

**Author:** ![stevel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/4491bb/32.png) [@stevel](https://www.ruby-forum.com/u/stevel)\
**Post date:** [September 3, 2008, 7:53pm UTC](https://www.ruby-forum.com/t/validates-uniqueness-of-in-update/147523/2 "2008-09-03T19:53:24Z")

</div>

Found the reason why it wasn’t working in the Update mode. There was  
another record with the same field value as the one that I was  
updating. I missed that test record previously created. Once I remove  
all duplicated records, the validate\_uniqueness\_of works as expected  
in the Update.

Steve

---

<div class="post-metadata">

**Author:** ![stevel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/4491bb/32.png) [@stevel](https://www.ruby-forum.com/u/stevel)\
**Post date:** [September 3, 2008, 9:55pm UTC](https://www.ruby-forum.com/t/validates-uniqueness-of-in-update/147523/3 "2008-09-03T21:55:23Z")

</div>

On Sep 3, 7:52 pm, stevel [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Found the reason why it wasn’t working in the Update mode. There was  
> another record with the same field value as the one that I was  
> updating. I missed that test record previously created. Once I remove  
> all duplicated records, the validate\_uniqueness\_of works as expected  
> in the Update.

Consider putting a unique index on your unique columns in the  
database.

Christian
