Sorry I had missed the context. Now I understand. The point is, you cannot 
catch this exception and expect things will work. The DB will enforce the 
reference. Catching the web2py exception does not mean the db will do it.

You have two options:

1) 

ondelete = "SET NULL"

This should work but you cannot just add it because web2py does not do 
migration when ondelete changes. You have to delete your database, you 
.tables and start again.

2) set to null manually:

def ondelete_func(form):
    for field in form.table._referenced_by:
        db(field==form.record_id).update(**{field.name:None})
    
def create_update():
    """create update funciton"""
    #crud.settings.update_ondelete = StorageList()
    form = crud.update(db[request.args(0)], request.args(1), 
ondelete=ondelete_func)
    return dict(form=form)


On Wednesday, 12 December 2012 08:37:46 UTC-6, Richard wrote:
>
> I am searching a way to avoid this kind of ticket in web2py :
>
> <class 'psycopg2.IntegrityError'> ERREUR: UPDATE ou DELETE sur la table « 
> table2 » viole la contrainte de clé étrangère « table3_field2t3_fkey » de 
> la table « table3 » DETAIL: La clé (id)=(1) est toujours référencée à 
> partir de la table « table3 ». 
>
> See this thread :
>
> https://mail.google.com/mail/?shva=1#search/ondelete/13b86b9d988ec725
>
> Thanks
>
> Richard
>
> On Tue, Dec 11, 2012 at 6:33 PM, Massimo Di Pierro 
> <massimo....@gmail.com<javascript:>
> > wrote:
>
>> Can you explain us what is the purpose of this code?
>
>
>

-- 



Reply via email to