If you use archive you should not never delete records. You should only have an "active" field and filter out the inavtice ones.
On Mar 8, 11:33 pm, Rowdy <[email protected]> wrote: > Greetings, > > I have been playing a little with crud.archive, as advertised by Massimo > in a post on 13-Feb-2010. It's fantastic :-) > > ... except when deleting data. > > When I try to delete, I get this: > > Traceback (most recent call last): > File "/home/rowdy/web2py/gluon/restricted.py", line 173, in restricted > exec ccode in environment > File > "/home/rowdy/web2py/applications/webacc2/controllers/table_codes.py", > line 652, in <module> > File "/home/rowdy/web2py/gluon/globals.py", line 96, in <lambda> > self._caller = lambda f: f() > File "/home/rowdy/web2py/gluon/tools.py", line 1892, in f > return action(*a, **b) > File > "/home/rowdy/web2py/applications/webacc2/controllers/table_codes.py", > line 364, in project_update > form = crud.update(db.project, row, onaccept = crud.archive) > File "/home/rowdy/web2py/gluon/tools.py", line 2391, in update > onaccept(form) > File "/home/rowdy/web2py/gluon/tools.py", line 2295, in archive > id = archive_table.insert(**new_record) > File "/home/rowdy/web2py/gluon/sql.py", line 1879, in insert > self._db._execute(query) > File "/home/rowdy/web2py/gluon/sql.py", line 958, in <lambda> > self._execute = lambda *a, **b: self._cursor.execute(*a, **b) > IntegrityError: insert or update on table "project_archive" violates > foreign key constraint "project_archive_current_record_fkey" > DETAIL: Key (current_record)=(31372) is not present in table "project". > > Actually I would expect this. When Crud.archive() inserts data into the > archive table, it populates the 'current_record' column with the id of > the row that has just been deleted from the main table. Thus the > foreign key constraint fails, with the above error. > > I am not sure if the following is the most web2pythoninc way of fixing > it, but I implemented the following work-around in Crud.archive() just > after the test for "if not old_record": > > if form.request_vars.delete_this_record == 'on': > return None > > Rowdy -- You received this message because you are subscribed to the Google Groups "web2py-users" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/web2py?hl=en.

