Based on your model, records in table2 are parent records, and records in
table3 are child records. I think the ondelete means on_parent_delete.
Mark
On Tuesday, December 11, 2012 10:42:47 AM UTC-5, Richard wrote:
>
> Here the error <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 ».
>
> Here the code :
>
> # Model
>
> db.define_table('table1',Field('fieldt1','string'), format='%(fieldt1)s')
>
> db.define_table('table2',Field('fieldt2','string'), Field('field2t2',
> 'reference table1', ondelete='NO ACTION'), format='%(fieldt2)s')
>
> db.define_table('table3',Field('fieldt3','string'), Field('field2t3',
> 'reference table2', ondelete='NO ACTION'), format='%(fieldt3)s')
>
> # Controller
>
> def create_update():
> """create update funciton"""
> form = crud.update(db[request.args(0)], request.args(1))
> return dict(form=form)
>
> I attach the app...
>
> The problem arrive when I try to delete a record in table2 that is
> attached to a record in table 3.
>
> I can make a function that will check if this record is attached by a
> record in table 3 before trying to deleted it, but I am curious to know if
> there is an other solution.
>
> The database is Postgres.
>
> I just test with SQLite and it is even worse, deletion of the referenced
> record is allowed but the record in the table 3 still reference the record.
> Form my point of view deletion of a record referenced shouldn't be allowed
> if there is a ondelete clause apply to the reference field. I also try to
> change the 'NO ACTION' for 'CASCADE' and if I delete a record of table 3
> that reference table2 record the referenced table 2 record doesn't get
> deleted (still with SQLite).
>
> I use web2py 2.2.1 for all these test.
>
> Hope my model is correct.
>
> I just test also with Postgres (8.4) and even when CASCADE is setted the
> referenced records are not deleted on deletion.
>
> Thanks
>
> Richard
>
> On Mon, Dec 10, 2012 at 5:28 PM, Niphlod <[email protected]
> <javascript:>>wrote:
>
>> we should see the model and the traceback. Some db engines are more
>> permissive than others. Often the cause of the issue is some sort of
>> "unique" or "notnull" costraint set on the referenced table.
>>
>>
>> On Monday, December 10, 2012 10:30:15 PM UTC+1, Richard wrote:
>>>
>>> Hello,
>>>
>>> My app raise issue when someone delete a record referenced by a other
>>> table. I this table I set for the reference field ondelete='NO ACTION', but
>>> as far as I understand it not solve noting since table1 (the referenced
>>> table) will not look at table2 definition to know what todo on delete.
>>>
>>> What should I do to make sure my app not raise issue on delete of a
>>> record if the record someone try to delete could not be deleted because it
>>> is referenced by an other table?
>>>
>>> Do I have to write my own function and trigger it with ondelete option
>>> of crud.update or SQLFORM?
>>>
>>> Thanks
>>>
>>> Richard
>>>
>> --
>>
>>
>>
>>
>
>
--