rails3 data inserting issues

5 views
Skip to first unread message

amvis

unread,
Mar 2, 2012, 4:35:20 AM3/2/12
to rubyonra...@googlegroups.com
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.....?

Juan Pablo Avello

unread,
Mar 2, 2012, 5:58:57 AM3/2/12
to rubyonra...@googlegroups.com
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.



Reply all
Reply to author
Forward
0 new messages