I wan't to clean up my database trough an script with i want to use as a 
data generator for demo purposes it work's fine wth SQLite but with Mysql 
got a lot of error's:

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)


With mysql:

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`))')


 

El viernes, 21 de abril de 2017, 11:18:30 (UTC-4), Massimo Di Pierro 
escribió:
>
> In the case of sqlite it is easy enough to also delete the content of the 
> databases/ folder.
>
> On Sunday, 16 April 2017 09:37:11 UTC-5, Matthew J Watts wrote:
>>
>> I had to log out of my webapp before deleting the database data, 
>> otherwise i would get an error message
>>
>> cheers
>>
>> On Monday, November 14, 2011 at 1:38:15 AM UTC+1, Archibald Linx wrote:
>>>
>>> Dear Web2py users, 
>>>
>>> How can I reset the database of my Web2py project ? 
>>>
>>> Thanks, 
>>> Archibald
>>
>>

-- 
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/d/optout.

Reply via email to