# Validates\_uniqueness\_of and attr\_readonly

**URL:** <https://www.ruby-forum.com/t/validates-uniqueness-of-and-attr-readonly/171459>\
**Category:** Rails\
**Created:** [July 2, 2009, 10:14pm UTC](https://www.ruby-forum.com/t/validates-uniqueness-of-and-attr-readonly/171459 "2009-07-02T22:14:16Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Learn\_by\_D](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/e274bd/32.png) [@Learn\_by\_D](https://www.ruby-forum.com/u/Learn_by_D)\
**Post date:** [July 2, 2009, 10:14pm UTC](https://www.ruby-forum.com/t/validates-uniqueness-of-and-attr-readonly/171459/1 "2009-07-02T22:14:16Z")

</div>

I notice that I always want to prevent the unique key of a table from  
being changed. Does that mean I always have to have attr\_readonly right  
after validates\_uniqueness\_of ? Is there a single function that  
replaces both of these but has the same affect?

Thanks.

* * *

Developing with Rails 2.3.2; Ruby 1.8.7 (2009-04-08 patchlevel 160)  
[powerpc-darwin9]
