You'd need to find out which tables are referencing the particular table that you can't truncate, and truncate those tables first.
On Tuesday, October 15, 2013 12:41:31 PM UTC-7, Auden RovelleQuartz wrote: > > thanks for the response Derek, > > I am using PostgreSQL with web2py > > how would I do what you recommend regarding "setting to cascade"? > > On Tuesday, October 15, 2013 1:36:55 PM UTC-5, Derek wrote: >> >> Well, I don't see the error in the code, but if the error you are getting >> is 'foreign key constraint' then the problem is you are trying to truncate >> tables that are used as foreign keys for other tables. You generally have >> to truncate those tables that are referencing the table in question first >> (the order of operations is important) and then you can truncate those >> tables. This is also a side effect of having the foreign key referential >> actions set to 'no action' or 'restrict'. You'd want it to 'cascade' if you >> want to delete items in this manner, otherwise, you must reorder your >> operations to delete the leaf rows first. >> >> On Tuesday, October 15, 2013 10:45:57 AM UTC-7, Auden RovelleQuartz wrote: >>> >>> >>> when I run this function, >>> >>> *def truncate_db_tables(the_db):* >>> * for table_name in the_db.tables():* >>> * the_db[table_name].truncate()* >>> * the_db.commit()* >>> * return()* >>> >>> >>> I get the following error (traceback provided below) - does anyone >>> understand what this means? >>> >>> Traceback >>> >>> 1. >>> 2. >>> 3. >>> 4. >>> 5. >>> 6. >>> 7. >>> 8. >>> 9. >>> 10. >>> 11. >>> 12. >>> 13. >>> 14. >>> 15. >>> 16. >>> 17. >>> 18. >>> 19. >>> 20. >>> 21. >>> 22. >>> 23. >>> 24. >>> 25. >>> 26. >>> 27. >>> 28. >>> 29. >>> 30. >>> 31. >>> 32. >>> 33. >>> 34. >>> 35. >>> 36. >>> 37. >>> 38. >>> 39. >>> 40. >>> 41. >>> 42. >>> 43. >>> 44. >>> 45. >>> 46. >>> >>> Traceback (most recent call last): >>> File "/home/www-data/web2py/gluon/restricted.py", line 212, in restricted >>> exec ccode in environment >>> File >>> "/home/www-data/web2py/applications/omniavx/controllers/developer.py" >>> <https://omniavx.com/admin/default/edit/omniavx/controllers/developer.py>, >>> line 353, in <module> >>> File "/home/www-data/web2py/gluon/globals.py", line 194, in <lambda> >>> self._caller = lambda f: f() >>> File >>> "/home/www-data/web2py/applications/omniavx/controllers/developer.py" >>> <https://omniavx.com/admin/default/edit/omniavx/controllers/developer.py>, >>> line 115, in testview5 >>> default_database_state_dev00() >>> File "/home/www-data/web2py/applications/omniavx/models/res_alpha.py" >>> <https://omniavx.com/admin/default/edit/omniavx/models/res_alpha.py>, line >>> 40, in default_database_state_dev00 >>> default_database_state_a00() >>> File "/home/www-data/web2py/applications/omniavx/models/res_alpha.py" >>> <https://omniavx.com/admin/default/edit/omniavx/models/res_alpha.py>, line >>> 27, in default_database_state_a00 >>> default_database_state_dev99() >>> File "/home/www-data/web2py/applications/omniavx/models/res_alpha.py" >>> <https://omniavx.com/admin/default/edit/omniavx/models/res_alpha.py>, line >>> 46, in default_database_state_dev99 >>> truncate_db_tables(db) >>> File "/home/www-data/web2py/applications/omniavx/models/res_alpha.py" >>> <https://omniavx.com/admin/default/edit/omniavx/models/res_alpha.py>, line >>> 2718, in truncate_db_tables >>> the_db[table_name].truncate() >>> File "/home/www-data/web2py/gluon/dal.py", line 8648, in truncate >>> return self._db._adapter.truncate(self, mode) >>> File "/home/www-data/web2py/gluon/dal.py", line 1425, in truncate >>> self.execute(query) >>> File "/home/www-data/web2py/gluon/dal.py", line 1784, in execute >>> return self.log_execute(*a, **b) >>> File "/home/www-data/web2py/gluon/dal.py", line 1778, in log_execute >>> ret = self.cursor.execute(command, *a[1:], **b) >>> File "/home/www-data/web2py/gluon/contrib/pg8000/dbapi.py", line 246, in >>> _fn >>> return fn(self, *args, **kwargs) >>> File "/home/www-data/web2py/gluon/contrib/pg8000/dbapi.py", line 317, in >>> execute >>> self._execute(operation, args) >>> File "/home/www-data/web2py/gluon/contrib/pg8000/dbapi.py", line 322, in >>> _execute >>> self.cursor.execute(new_query, *new_args) >>> File "/home/www-data/web2py/gluon/contrib/pg8000/interface.py", line 399, >>> in execute >>> self._stmt.execute(*args, **kwargs) >>> File "/home/www-data/web2py/gluon/contrib/pg8000/interface.py", line 169, >>> in execute >>> self._row_desc, cmd = self.c.bind(self._portal_name, >>> self._statement_name, args, self._parse_row_desc, kwargs.get("stream")) >>> File "/home/www-data/web2py/gluon/contrib/pg8000/protocol.py", line 943, >>> in _fn >>> return fn(self, *args, **kwargs) >>> File "/home/www-data/web2py/gluon/contrib/pg8000/protocol.py", line 1142, >>> in bind >>> return reader.handle_messages() >>> File "/home/www-data/web2py/gluon/contrib/pg8000/protocol.py", line 911, >>> in handle_messages >>> retval = handler(msg, *args, **kwargs) >>> File "/home/www-data/web2py/gluon/contrib/pg8000/protocol.py", line 1181, >>> in _bind_nodata >>> reader.handle_messages() >>> File "/home/www-data/web2py/gluon/contrib/pg8000/protocol.py", line 916, >>> in handle_messages >>> raise exc >>> P >>> >>> -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/groups/opt_out.

