Hi Annet, because of the writable=False on unique_id.
When you do that then the field is not included in the form and it is not checked on a request, so the form is accepted based on the other fields and the error is the result of the enforcement of unique=True at the DB level on the auto insert. Denes. On Nov 17, 3:35 am, annet <[email protected]> wrote: > I set up a mock app to help someone solve a problem. > > In db.py I defined these two tables after all the mail, auth and crud > stuff: > > db.define_table('mockbio', > > Field('unique_id',type='integer',unique=True,writable=False,readable=True), > Field('first_name',length=24), > Field('last_name',length=72), > migrate='mockbio.table') > > db.mockbio.unique_id.default=auth.user_id > db.mockbio.unique_id.requires=IS_NOT_IN_DB(db,db.bio.unique_id) > db.mockbio.unique_id.label=T('Unique_id') > > Using web2py's administrative interface I am able to enter a record > for each user I created, when I enter a second record for a user I get > an error on the unique_id field: value already in database or empty. > > I also defined two functions in default.py: > > @auth.requires_login() > def create_mockbio_first(): > form=crud.create(table=db.mockbio) > return dict(form=form) > > @auth.requires_login() > def create_mockbio_second(): > form=SQLFORM(db.mockbio) > if form.accepts(request.vars, session): > session.flash = 'form accepted' > elif form.errors: > response.flash = 'form has errors' > else: > response.flash = 'please fill the form' > return dict(form=form) > > When I expose the functions, I can create a record for the logged in > user once, when I try to create a second record for the same user an > error ticket is issued: IntegrityError: column unique_id is not unique > > Why do I get an error ticket instead of an error message in the form? > > Kind regards, > > Annet

