* If you want to delete *content* of some specific table, use
``db.table.truncate()``, as DenesL says.
* If you want the DAL to recreate the whole table (with SQLite, the
allowed alters are limited, sometimes table drop is needed in order to
clean up): ``db.table.truncate()``
* If you want to completely destroy and recreate the whole database,
just empty the ``databases`` folder inside your application directory.
--
Samuele ~redShadow~ Santi
----------------------------------------------------------------
redshadow[at]hackzine.org - redshadowhack[at]gmail.com
Blog: http://hackzine.org
GPG Key signature:
050D 3E9F 6E0B 44CE C008 D1FC 166C 3C7E EB26 4933
----------------------------------------------------------------
/me recommends:
Squadra Informatica - http://www.squadrainformatica.com
----------------------------------------------------------------
- Proud ThinkPad T-Series owner
- Registered Linux-User: #440008
* GENTOO User since 1199142000 (2008-01-01)
* former DEBIAN SID user
----------------------------------------------------------------
"Software is like sex: it's better when it's free!"
-- Linus Torvalds
using sqlite. just go to /databases folder and delete everything there.
web2py will create it all again.
Web2py will recreate it next time you execute your app.
If it doesn't help, try something like that in web2py shell:
http://pastebin.com/w0q4yKkK
--
Vinicius Assef.
def limpiar_db(db, models):
for m in models:
l("Limpiando tabla: {}".format(m))
db[m].truncate()
db.commit()
a_limpiar = [
'almacenamiento', 'perfil',
'movimiento_inventario', 'componente_modelo_producto',
'componente', 'modelo_producto',
'auth_permission', 'auth_membership', 'auth_user', 'auth_group',
]
limpiar_db(db, a_limpiar)DEBUG:web2py.demo102017:Limpiando tabla: movimiento_inventario
DEBUG:web2py.demo102017:Limpiando tabla: componente_modelo_producto
DEBUG:web2py.demo102017:Limpiando tabla: componente
Traceback (most recent call last):
File "/opt/web-apps/web2py/gluon/shell.py", line 274, in run
execfile(startfile, _env)
File "applications/demo102017/private/generadordatos.py", line 150, in <module>
limpiar_db(db, a_limpiar)
File "applications/demo102017/private/generadordatos.py", line 137, in limpiar_db
db[m].truncate()
File "/opt/web-apps/web2py/gluon/packages/dal/pydal/objects.py", line 869, in truncate
return self._db._adapter.truncate(self, mode)
File "/opt/web-apps/web2py/gluon/packages/dal/pydal/adapters/base.py", line 824, in truncate
self.execute(query)
File "/opt/web-apps/web2py/gluon/packages/dal/pydal/adapters/__init__.py", line 67, in wrap
return f(*args, **kwargs)
File "/opt/web-apps/web2py/gluon/packages/dal/pydal/adapters/base.py", line 412, in execute
rv = self.cursor.execute(command, *args[1:], **kwargs)
File "/usr/lib64/python2.7/site-packages/MySQLdb/cursors.py", line 205, in execute
self.errorhandler(self, exc, value)
File "/usr/lib64/python2.7/site-packages/MySQLdb/connections.py", line 36, in defaulterrorhandler
raise errorclass, errorvalue
OperationalError: (1701, 'Cannot truncate a table referenced in a foreign key constraint (`demo102017`.`componente_modelo_producto`, CONSTRAINT `componente_modelo_producto_ibfk_1` FOREIGN KEY (`componente`) REFERENCES `demo102017`.`componente` (`id`))')