Enter from 0 to 255 characters on grid=SQLFORM How to fix?

67 views
Skip to first unread message

Austin Taylor

unread,
Apr 9, 2014, 2:54:40 AM4/9/14
to web...@googlegroups.com
I'm creating a grid using grid=SQLFORM.smartgrid(db.mydatabase, user_signature=True)

when I try to update one of the fields using the edit button I get enter from 0 to 255 characters. The field already has over 255 characters in it because its in the database, but I cannot add extra characters to the field.

Any help is appreciated. I looked all over for the error "enter from 0 to 255 characters"


Niphlod

unread,
Apr 9, 2014, 3:00:49 AM4/9/14
to web...@googlegroups.com
Field('whatever')

means really

Field('whatever', 'string', length=255)

it gets a default "requires" that resembles IS_LENGTH(maxsize=255)

if you need more of that, use length=morethan255

Austin Taylor

unread,
Apr 9, 2014, 3:06:12 AM4/9/14
to web...@googlegroups.com
Wow  thanks for the quick reply! I did try the length=499, but I still get the validator error. Do I need to restart web2py?

Niphlod

unread,
Apr 9, 2014, 8:09:19 AM4/9/14
to web...@googlegroups.com
what's the table definition ? what backend are you using ?

Austin Taylor

unread,
Apr 10, 2014, 9:43:33 AM4/10/14
to web...@googlegroups.com
Using MySQL and the table definition is just:

db.define_table('newtable',
     Field('Name','string'),
     Field('Comments', string', length=499)'
     migrate=False)

黄祥

unread,
Apr 10, 2014, 10:46:23 AM4/10/14
to web...@googlegroups.com
perhaps try to set migrat = True, to take effect for your defined table.

best regards,
stifan

Austin Taylor

unread,
Apr 10, 2014, 10:50:56 AM4/10/14
to web...@googlegroups.com
I only define the table in my db.py though. I don't see it referenced anywhere else.

黄祥

unread,
Apr 10, 2014, 10:57:18 AM4/10/14
to web...@googlegroups.com
i mean set the migrate = True, to take effect for your changes of define table field, or are you create it from the scratch?

best regards,
stifan

Austin Taylor

unread,
Apr 10, 2014, 10:58:25 AM4/10/14
to web...@googlegroups.com
I set migrate to True and checked the database logs. You're right... its showing as a VARCHAR 255. Even though I have length=499 defined in the db.define_table. Is web2py limited to 255 for VARCHARS?

黄祥

unread,
Apr 10, 2014, 11:05:29 AM4/10/14
to web...@googlegroups.com
please try to start from simple, create your new web2py application and then put your define table there, after that check your sql.log or test it from appadmin.
e.g.
models/db.py
db.define_table('newtable',
     Field('Name','string'),
     Field('Comments', string', length=499) )

best regards,
stifan

Austin Taylor

unread,
Apr 10, 2014, 12:52:13 PM4/10/14
to web...@googlegroups.com
Are there any other suggestions? I've tried everything and I really need help with this.

When the table is set to Migrate=True the sql log shows VARCHAR(255) even though my actual SQLDatabase shows 499 length and my length on the db model is set to length=500

Austin Taylor

unread,
Apr 10, 2014, 1:09:22 PM4/10/14
to web...@googlegroups.com
Fixed it by changing string to text.

Is there anything that could go wrong by me doing that?

Derek

unread,
Apr 11, 2014, 4:00:35 PM4/11/14
to web...@googlegroups.com
is this mssql or mysql or postgres? i think mysql has a limit of 255 for string data. it would silently change any lengths longer to 255...

Austin Taylor

unread,
Apr 11, 2014, 4:54:06 PM4/11/14
to web...@googlegroups.com

It's for mysql. Its stored as VARCHAR in the data base and up to 500 chars but fixing it to text in my db.py model fixed it. I'm guessing there is a built in validator for strings

--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to a topic in the Google Groups "web2py-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/d8G92qlxSjc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to web2py+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages