Then why did web2py fail with a run time error?  Or why wasn't the run
time error trapped?  Maybe because I had requires on the same table
for a different constraint?

It doesn't look good when visitors to your site see the web2py error
ticket page.  Adding the explicit constraint prevented that.  Without
the explicit constraint, attempting to add a duplicate category
produced an error because postgresql threw the error (correctly--it
was doing what is was told to do by rejecting a duplicate).

Should be easy to repro.

Thanks, Anthony.

P.S. - I am hanging in there and investing...


On Feb 8, 4:51 pm, Anthony <abasta...@gmail.com> wrote:
> > In line 14, db.image.title represents the field "title" of table
> > "image". The
> > attribute requires allows you to set requirements/constraints that
> > will be
> > enforced by web2py forms. Here we require that the "title" is unique:
> > IS_NOT_IN_DB(db, db.image.title)
> > Notice this is optional because it is set automatically given that
> > Field(’title’,
> > unique=True).
>
> The book says that explicitly adding the IS_NOT_IN_DB validator is optional
> because if you specify unique=True but do not explicitly specify any
> validators at all, the IS_NOT_IN_DB validator will be assigned
> automatically. For example:
>
> >>> db.define_table('user', Field('username', unique=True))
> >>> print db.user.username.requires
>
> [<gluon.validators.IS_NOT_IN_DB object at 0x000000000439D710>,
> <gluon.validators.IS_LENGTH object at 0x000000000439D5F8>]
>
> Notice that I did not specify the IS_NOT_IN_DB validator in the field
> definition, but it was added anyway because I set unique=True. Note, this
> only happens if you don't specify "requires" at all.
>
> Anthony

Reply via email to