# ignoring :limit on string field migrations for postgresql

**URL:** <https://discuss.rubyonrails.org/t/ignoring-limit-on-string-field-migrations-for-postgresql/22805>\
**Category:** rubyonrails-talk\
**Created:** [January 8, 2008, 1:21am UTC](https://discuss.rubyonrails.org/t/ignoring-limit-on-string-field-migrations-for-postgresql/22805 "2008-01-08T01:21:02Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![11175](https://avatars.discourse-cdn.com/v4/letter/1/8edcca/32.png) [@11175](https://discuss.rubyonrails.org/u/11175)\
**Post date:** [January 8, 2008, 1:21am UTC](https://discuss.rubyonrails.org/t/ignoring-limit-on-string-field-migrations-for-postgresql/22805/1 "2008-01-08T01:21:02Z")

</div>

By default, if a limit is not set on string fields in a migration, the limit is set to 255. In postgresql, varchar fields can vary without having a limit. Is it possible to write migrations that will keep the varchar varying without a default limit set?

Thanks, Nick

---

<div class="post-metadata">

**Author:** ![radar](https://sea2.discourse-cdn.com/rubyonrails/user_avatar/discuss.rubyonrails.org/radar/32/604_2.png) [@radar](https://discuss.rubyonrails.org/u/radar)\
**Post date:** [January 8, 2008, 1:31am UTC](https://discuss.rubyonrails.org/t/ignoring-limit-on-string-field-migrations-for-postgresql/22805/2 "2008-01-08T01:31:48Z")

</div>

Try specifying :default =\> nil

---

<div class="post-metadata">

**Author:** ![11175](https://avatars.discourse-cdn.com/v4/letter/1/8edcca/32.png) [@11175](https://discuss.rubyonrails.org/u/11175)\
**Post date:** [January 8, 2008, 1:45am UTC](https://discuss.rubyonrails.org/t/ignoring-limit-on-string-field-migrations-for-postgresql/22805/3 "2008-01-08T01:45:31Z")

</div>

:default =\> nil didn't work. I had already tried :limit =\> nil and that didn't work either. I also tried :limit =\> nil, :default =\> nil. Still no luck, the varchar length is still being set at 255. I may just have to write all of my varchar fields as sql within the migration files instead of using ruby code, but I am hoping to avoid that.

I might try to find the migration code and see if it is possible to add fix, but I don't know if this wold be considered a bug or not and I haven't gotten my feet wet in rails src code yet.

Nick

Ryan Bigg wrote:

---

<div class="post-metadata">

**Author:** ![11175](https://avatars.discourse-cdn.com/v4/letter/1/8edcca/32.png) [@11175](https://discuss.rubyonrails.org/u/11175)\
**Post date:** [January 16, 2008, 8:51pm UTC](https://discuss.rubyonrails.org/t/ignoring-limit-on-string-field-migrations-for-postgresql/22805/4 "2008-01-16T20:51:08Z")

</div>

Nick Berveiler wrote:

> I might try to find the migration code and see if it is possible to add a :limit =\> :ignore param or something like that and submit it as a bug fix, but I don't know if this wold be considered a bug or not and I haven't gotten my feet wet in rails src code yet.

I put this in an initializer:

\<pre\> module ActiveRecord::ConnectionAdapters

&nbsp;&nbsp;class PostgreSQLAdapter \< AbstractAdapter

&nbsp;&nbsp;&nbsp;&nbsp;# Monkey patched to remove varchar limit of 255 that Rails set, since &nbsp;&nbsp;&nbsp;&nbsp;# it makes no performance difference in Postgres. &nbsp;&nbsp;&nbsp;&nbsp;def native\_database\_types #:nodoc: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:primary\_key =\> "serial primary key", &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:string =\> { :name =\> "character varying" }, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:text =\> { :name =\> "text" }, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:integer =\> { :name =\> "integer" }, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:float =\> { :name =\> "float" }, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:decimal =\> { :name =\> "decimal" }, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:datetime =\> { :name =\> "timestamp" }, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:timestamp =\> { :name =\> "timestamp" }, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:time =\> { :name =\> "time" }, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:date =\> { :name =\> "date" }, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:binary =\> { :name =\> "bytea" }, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:boolean =\> { :name =\> "boolean" } &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} &nbsp;&nbsp;&nbsp;&nbsp;end

&nbsp;&nbsp;end

end \</pre\>
