On Tuesday, January 10, 2017 at 3:07:17 PM UTC-8, Rahul Priyadarsi wrote:
>
> Here is my db.py:
>
> db.define_table('antenna_details',
>                 Field('antenna_name',required=True),
>                 Field('model_name',required=True),
>                 Field('project_name',required=True),
>                 Field('frequency_band',required=True),
>                 Field('polarization',required=True),
>                 Field('aperture_size',required=True),
>                 Field('fixer_availability',required=True),
>                 Field('weight',required=True),
>                 Field('material',required=True),
>                 
> Field('email_id',required=True,unique=True,requires=[IS_NOT_IN_DB]),
>                 Field('subject',type='text',required=True),
>                 Field('attached',type='upload', label="""
>                     Antenna/feed Geometry
>                     Electrical specification
>                     Attach Simulated data in predicted form
>                 """)
> )
>
> db.antenna_details.email_id.requires=[IS_EMAIL(),IS_NOT_EMPTY()]
> db.antenna_details.attached.requires=IS_NOT_EMPTY()
> db.antenna_details.subject.rquires=IS_NOT_EMPTY()
> db.antenna_details.material.requires=IS_NOT_EMPTY()
> db.antenna_details.weight.requires=IS_NOT_EMPTY()
> db.antenna_details.fixer_availability.requires=IS_NOT_EMPTY()
> db.antenna_details.aperture_size.requires=IS_NOT_EMPTY()
> db.antenna_details.polarization.requires=IS_NOT_EMPTY()
> db.antenna_details.frequency_band.requires=IS_NOT_EMPTY()
> db.antenna_details.project_name.requires=IS_NOT_EMPTY()
> db.antenna_details.model_name.requires=IS_NOT_EMPTY()
>
> [...]
> My problem is that when I submit a form with duplicate email id(that 
> already exists in db), instead of redirecting back to form and showing the 
> error, it generates a ticket like this:
>
> <class 'sqlite3.IntegrityError'> column email_id is not unique
>
> While if I submit with empty fields, it simply redirects to the form and 
> shows errors besides the respective input tags in red.
> Why is it happening like this for email_id field only? And how do I 
> disable this to show error messages in form itself?
>


You have unique=True for the email_id field, and my understanding is that 
is enforced by the database engine, not the DAL.

I don't have an explanation for why the IS_NOT_IN_DB() didn't exclude that 
before the update.  Unless it is the .process() when you create the form.

/dps

-- 
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 the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to