records-delete/truncate postgres table in appadmin

71 views
Skip to first unread message

Mirek Zvolský

unread,
Aug 22, 2016, 7:31:50 AM8/22/16
to web2py-users
I am trying delete all records with appadmin.
Error message is not very descriptive.
Any idea?


Traceback (most recent call last):
  File "/home/www-data/web2py/gluon/main.py", line 464, in wsgibase
    session._try_store_in_db(request, response)
  File "/home/www-data/web2py/gluon/globals.py", line 1180, in _try_store_in_db
    if not table._db(table.id == record_id).update(**dd):
  File "/home/www-data/web2py/gluon/packages/dal/pydal/objects.py", line 2054, in update
    ret = db._adapter.update("%s" % table._tablename, self.query, fields)
  File "/home/www-data/web2py/gluon/packages/dal/pydal/adapters/base.py", line 1031, in update
    raise e
ProgrammingError: ('ERROR', '25P02', 'current transaction is aborted, commands ignored until end of transaction block')

ln 1026 - 1035:
        except Exception:
            e = sys.exc_info()[1]
            table = self.db[tablename]
            if hasattr(table,'_on_update_error'):
                return table._on_update_error(table,query,fields,e)
            raise e

        try:
            return self.cursor.rowcount
        except:
            return None

Mirek Zvolský

unread,
Aug 22, 2016, 7:40:02 AM8/22/16
to web2py-users
Probably something with foreign key integrity (cascade, restrict, ...) because after deleting of records in other tables it works.
However, how to understand such error tickets?



Dne pondělí 22. srpna 2016 13:31:50 UTC+2 Mirek Zvolský napsal(a):

黄祥

unread,
Aug 22, 2016, 5:32:03 PM8/22/16
to web2py-users
this is what i do in dev environment :
controllers/truncate.py
from gluon.admin import *
auth.requires(has_membership_admin)(lambda: None)()
def index():
for table in db.tables:
db[table].truncate()
app = request.application
clean = app_cleanup(app, request)
redirect(URL('default', 'index') )

best regards,
stifan

Alex Glaros

unread,
Aug 24, 2016, 5:44:51 PM8/24/16
to web2py-users
what does app_cleanup do?

can I truncate only one table and then run this one line clean = app_cleanup(app, request)?

thanks

Alex Glaros

黄祥

unread,
Aug 24, 2016, 7:38:39 PM8/24/16
to web2py-users
app_cleanup is the admin function cleanup to clean session, cache, dll (same like on admin page).
yes, you can, app_cleanup is a prevention, because i created the function that truncate all tables including auth_user, so while u are logged in and run truncate for all table it will raises an error after it done, said about privilege because the auth user is empty now.

best regards,
stifan
Reply all
Reply to author
Forward
0 new messages