Ruby on Rails Friday, March 2, 2012


El viernes 2 de marzo de 2012 10:35:20 UTC+1, amvis escribió:

I am using rails3. when i am trying to insert data into postgrsql got the error like this


PGError: ERROR:  value too long for type character varying(15)

In the migration file have  t.string :contact_number,:limit=>15,:null=>false. this string because the contact_number will be +91 9387292839. Why getting like this.....?

The given error is quite self descriptive: the attribute size limit is 15 characters and you try to assign a longer string to it. Postgres raises an exception instead of just cutting it to 15 characters as mysql(for instance) would do.

You either shouldnt limit your strings or should add a length validation to your model. 
String defaults to 255; should you need more characters, you'd better use Text as type.

Personally, I don't think its worth to limit strings and save a few bytes in your db nowadays.



--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/iJsqOoPw5ikJ.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

No comments:

Post a Comment