Strange error: "SQLTable: no field is required"

0 views
Skip to first unread message

voltron

unread,
Feb 27, 2008, 8:19:24 AM2/27/08
to web2py Web Framework
I have defined required constraints for the form and table. Is there
another reason why this error would occur?


Thanks

Massimo Di Pierro

unread,
Feb 27, 2008, 11:11:21 AM2/27/08
to web...@googlegroups.com
There are SQLField attributes

requires a validator (enforced at the level of forms)

required True or False (enforced by insert)

notnull True or False (enforced by database)

They are logically different. If a field is required, it does not
matter what value it has (it can be null unless notnull=True) but, if
it does not have a default, it must be set.

Do not mistype requires as required

Massimo

voltron

unread,
Feb 27, 2008, 11:18:16 AM2/27/08
to web2py Web Framework
Hmm, I dont get it, I have defaults for fields that are not required:

db_siteadmin.define_table('cms_users',
SQLField('user_name' , 'string', length = 50, required
= True, unique = True),
SQLField('password' , 'password', length = 128),
SQLField('email' , 'string', length=255, required
= True, unique = True),
SQLField('group_type' , 'string', length=50),
SQLField('is_active' , 'boolean', default=True),
SQLField('created_on' , 'date',
default=datetime.date.today()),
SQLField('modified_on' , 'date'),
migrate = migrate_value
)
db_siteadmin.cms_users.user_name.requires =
[IS_NOT_IN_DB(db_siteadmin, 'cms_users.user_name'), IS_NOT_EMPTY()]
db_siteadmin.cms_users.email.requires =
[IS_NOT_IN_DB(db_siteadmin, 'cms_users.email'), IS_EMAIL(),
IS_NOT_EMPTY()]


and this is the form:

form = FORM(
FIELDSET(
LABEL(T('User name'), _for="user_name"),
INPUT(_name="user_name", _size="40",
requires=[IS_NOT_EMPTY(),
IS_NOT_IN_DB(db_siteadmin,'cms_users.user_name')]),
LABEL(T("Email"), _for="email"),
INPUT(_name="email", _size="40",
requires=[IS_NOT_EMPTY(),
IS_NOT_IN_DB(db_siteadmin,'cms_users.email'), IS_EMAIL()]),
LABEL(T("Password"), _for="password"),
INPUT(_name="password", _size="20", _type =
"password", requires = [IS_NOT_EMPTY(), IS_ALPHANUMERIC(), CRYPT()]),
LABEL(T("Repeat password"), _for="password2"),
INPUT(_name="password2", _size="20", _type =
"password", requires = [IS_NOT_EMPTY(), IS_ALPHANUMERIC(), CRYPT()]),
INPUT(_type="submit", _value=T('Add user')),
_name="adduser_form"
)

voltron

unread,
Mar 1, 2008, 1:10:52 PM3/1/08
to web2py Web Framework
Anybody have an idea what I am doing wrong here?

Thanks

Massimo Di Pierro

unread,
Mar 1, 2008, 10:22:50 PM3/1/08
to web...@googlegroups.com
Could you summarize again what was the problem with this code?

voltron

unread,
Mar 1, 2008, 11:28:23 PM3/1/08
to web2py Web Framework
I was getting this error:

SQLTable: no field is required

I dont know why

Massimo Di Pierro

unread,
Mar 2, 2008, 12:04:52 AM3/2/08
to web...@googlegroups.com
You must be creating and processing an SQLFORM without one of the
required fields. Try remove all the requires=True statements, and add
them one by one to see which one is giving problems.

Massimo

Reply all
Reply to author
Forward
0 new messages