db[t.requirements].requirement_priority_id.required = IS_NULL_OR(... should be db[t.requirements].requirement_priority_id.requires = IS_NULL_OR(...
On Tuesday, November 27, 2012 4:11:51 PM UTC-5, israelord wrote: > > Hi there! and greetings from Caracas - Venezuela, > > I started using web2py recently thanks to a project at the office, I find > it very easy > to use and I'm actualy liking it. > > The thing is that I defined a table, with a *reference* field which > accepts null values and, > for some reason, when it's null, I get the following integrity error: > > <class 'psycopg2.IntegrityError'> insert or update on table "requirements" > violates foreign key constraint "requirements_requirement_priority_id_fkey" > DETAIL: Key (requirement_priority_id)=(0) is not present in table > "requirement_priorities". > > I've been reading for a while, I haven't found so much information, I > found someone who had the same issue[0] and someone who tried to help[1], > but I tried what he told and it didn't work for me. > > Here is my table definition: > > db.define_table(t.requirements > ,Field('num_invoice', 'string', default = '', label = > T('Invoice Number'), \ > required = False) > ,Field('total_invoice', 'decimal(10,4)', default = 0, label = > T('Invoice Total'), \ > required = False) > ,Field('requested_payment', 'decimal(10,4)', default = 0, > label = T('Requested Payment'), \ > required = True, notnull = True) > ,Field('approved_payment', 'decimal(10,4)', default = 0, label > = T('Approved Payment'), \ > required = True, notnull = True) > ,Field('description', 'string', length = 1024,default = '', > label = T('Description'), \ > required = True, notnull = True, widget = > SQLFORM.widgets.text.widget) > ,Field('reminder_call_count','integer', default = 0, label = > T('Reminder Call Count'), \ > required = True, notnull = True) > ,Field('status_id','reference %s' % t.status, default = 1, > label = T('Status'), \ > required = True, notnull = True) > ,Field('requirement_type_id', 'reference %s' % > t.requirement_types, default = 1, label = T('Requirement Type'), \ > required = True, notnull = True) > ,Field('requirement_priority_id', 'reference %s' % > t.requirement_priorities, label=T("Requirement Priority")) > ,auth.signature) > > The problematic field is "requirement_priority_id", and this is how I > defined the validators for this field > > db[t.requirements].requirement_priority_id.required = > IS_NULL_OR(IS_IN_DB(db, '%s.name' % t.requirement_priorities, \ > zero=T('Choose One'))) > > I also tried adding required=False, notnull=False and default=None in the > Field definition and I still had the same problem. > > I searched and tried to debug web2py code, searching for any > safe_int(value) or something like that, but I got nothing, > I searched on the files html.py, sqlhtml.py and in the FORM class, on the > validate() and process() methods. > > Can somebody give me a light on this? > > Thank you in advance for your time. > > [0] http://www.mail-archive.com/web2py@googlegroups.com/msg67428.html > [1] http://www.mail-archive.com/web2py@googlegroups.com/msg67745.html > --